...

View Full Version : PHP send mail script is annoying me



sirborder
11-18-2006, 10:56 AM
I am really getting annoyed here. Could anybody help me figure out the problem?

Go to http://surfacehawaii.com/contactus.html
Fill out the form and submit.

See?

Here is the php code


<?php
if(isset($_POST['submit']))*{
*

$to*=*"caleb@surfacehawaii.com";
$subject*=*"Contact Form";
$name_field*=*$_POST['name'];
$email_field*=*$_POST['email'];
$message*=*$_POST['message'];
*
foreach($_POST['check']*as*$value)*{

$check_msg*.=*"Checked:*$value\n";

}
*
$body*=*"From:*$name_field\n*E-Mail:*$email_field\n*Message:\n*$message\n*$check_msg";*
mail($to,*$subject,*$body);*

if*(mail($to,*$subject,*$body))*//if*the*mails*sent
{*header(Location*:*"http://www.surfacehawaii.com/thanks.html");
}
//page*to*redirect*to*if*your*email*was*sent
else
{*echo*"Sorry.*Error*sending*message!";}*//show*that*email*could*not*be*sent**

?>

If anyone could help, that would be great.

sirborder
11-18-2006, 11:22 AM
OK
New php script, but still have a problem.


<?php*
$to*=*"caleb@surfacehawaii.com";
$Subject*=*"{$_POST['subject']}";
$message*=*"NAME:*{$_POST['name']}*{$_POST['message']},";
mail($to,$Subject,$message);
if(mail){
echo*"<BR*/>Thanks,*message*sent";
}
else{
echo*"<BR*/>*An*Error*occured";
}
?>

Thanks in advance for your patience.

ess
11-18-2006, 12:23 PM
You should have looked at the PHP documentation (http://uk.php.net/manual/en/function.mail.php).

The mail function signature is specified as follow.


bool mail ( string to, string subject, string message [, string additional_headers [, string additional_parameters]] )

Therefore, you need to re-write your script in accordance to the mail function signature. Here is an example


<?php
$to = 'caleb@surfacehawaii.com';
$subject = $_POST['subject'];
$message = $_POST['message'];
$headers = 'From: contact@surfacehawaii.com' . "\r\n" .
'Reply-To: ' . $_POST['name'] . '<'. $_POST['email'] .'>' . "\r\n" .
'X-Mailer: PHP/' . phpversion();

$ok = mail($to, $subject, $message, $headers);
if( $ok ) {
echo "Thanks, message sent successfully";
} else {
echo "Sorry, unable to send email at the moment.";
}
?>

Note: I took the liberty to define another post variable $_POST['email'], so that when you receive an email, you can easily reply to the person who has emailed you.

Good luck.
Ess



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum