Jump to content

PHP newbie.


bator

Recommended Posts

Hey guys, I'm trying to make a simple email script and I'm sure I'm overlooking something easy and I know one of you PHP Gurus can get this in a second.

 

I have my HTML file with a form action for mailer.php the code for mailer.php is

 

<?php
$to      = '[email protected]';
$subject = 'hello';
$message = 'this is the email message to php freaks.!';
$headers = 'From: [email protected]' . "\r\n" .
    'Reply-To: [email protected]' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
?> 

 

My question is, on the HTML file in the form, How can I get data from the website to be put into $to $subject, etc. I'm not sure how to link the two so that data i type in the text field will replace whats in the mailer.php script. I set the text field name to subject, etc but I'm just not knowledgeable enough to get it.

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/63262-php-newbie/
Share on other sites

I'll get you started....

 

The html file:

<form name="email_form" method="post" action="send_email.php">

Email address: <input type="text" name="email_to" size="50"/>

<!-- subject and message inputs go here -->

<p><input type="submit" name="submit" id="submit" value="Submit;" /></p>

</form>

 

the php file called "send_email.php"

<?php

$email_to = mysql_real_escape_string($_POST['email_to']); 
if (empty($email_to))
{ die('Email is empty. Please go <a href="javascript:history.back(-1);">back</a>.');
}

//  add above for subject and message

$to      = '[email protected]';
$subject = 'hello';
$message = 'this is the email message to php freaks.!';
$headers = 'From: [email protected]' . "\r\n" .
'Reply-To: [email protected]' . "\r\n" .
'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
?> 

 

Link to comment
https://forums.phpfreaks.com/topic/63262-php-newbie/#findComment-316294
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.