Jump to content

mail() not working properly


evilandy

Recommended Posts

so, I'm working on a contact form and I finished my code and everything andd it looks fine but it gives me an error on the line with the actual mail() function
[code]<?php
$name=$_POST['name'];
$email=$_POST['senderemail'];
$subject=$_POST['subject'];
$reason=$_POST['reason'];
$message=$_POST['message'];
$message=wordwrap($message, 70);
$ip = getenv('REMOTE_ADDR');

if ($reason == 'nothingselected') {
    echo "You must select a reason for contact to procede. <a href=\"contact.html\">Go Back.</a>";
}
else {
    mail($reason, $subject, 'Sender: '$name'('$email')\n Sender\'s IP: '$ip'\n\nMessage: '$message, 'From: '$name 'Reply-To: '$email);
    echo "Thank you for your message.";
}
?>[/code]
can someone tell me whats wrong with it?
Link to comment
https://forums.phpfreaks.com/topic/6419-mail-not-working-properly/
Share on other sites

You should start with the reciepents email adress, read the manual on how to use the mail function: [a href=\"http://no.php.net/manual/en/function.mail.php\" target=\"_blank\"]http://no.php.net/manual/en/function.mail.php[/a]
[code]
<?php
$to      = '[email protected]';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: [email protected]' . "\r\n" .
   'Reply-To: [email protected]' . "\r\n" .
   'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
?>
[/code]
Its a mix with single quotes i imagine, try this:
[code]
$headers = "From: $name \r\n";
$headers .= "Reply-To: $email \r\n";

mail($reason, $subject, "Sender: $name ($email)\r\nSender IP: $ip\r\n\r\nMessage: $message", $headers);
[/code]

And you should consider adding some more headers to avoid spam filters, i also suggest to keep it tidy - putting everything written in between the mail function easily screws thing up.

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.