Jump to content


Photo

mail() not working properly


  • Please log in to reply
3 replies to this topic

#1 evilandy

evilandy
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 02 April 2006 - 09:57 PM

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
<?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.";
}
?>
can someone tell me whats wrong with it?

#2 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 02 April 2006 - 10:07 PM

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]
<?php
$to      = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
   'Reply-To: webmaster@example.com' . "\r\n" .
   'X-Mailer: PHP/' . phpversion();

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


#3 evilandy

evilandy
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 02 April 2006 - 10:19 PM

yes, $reason is the recipients email, it would make more sense if I posted the form, but besides that, is there anything wrong?

#4 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 02 April 2006 - 10:29 PM

Its a mix with single quotes i imagine, try this:
$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);

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users