evilandy Posted April 2, 2006 Share Posted April 2, 2006 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? Quote Link to comment Share on other sites More sharing options...
alpine Posted April 2, 2006 Share Posted April 2, 2006 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 = '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);?> [/code] Quote Link to comment Share on other sites More sharing options...
evilandy Posted April 2, 2006 Author Share Posted April 2, 2006 yes, $reason is the recipients email, it would make more sense if I posted the form, but besides that, is there anything wrong? Quote Link to comment Share on other sites More sharing options...
alpine Posted April 2, 2006 Share Posted April 2, 2006 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.