Page 1 of 1

php mail function help needed

Posted: Sun Feb 19, 2006 4:01 am
by Azlan
Hi, I am having problems using the mail() function. It all seems to work fine, but the email is not delivered. Can any one help?

Code: Select all

<?php
	
		function checkOK($field){
			if (eregi("\r",$field) || eregi("\n",$field)){
				die("Invalid Input at $field");
			}
		}

		//Create email message
		$to = "me@email.com";
		checkOK($to);
		$subject = "New order";
		checkOK($subject);
		$message = "Order placed by ";
		checkOK($message);
		$from = "orders@email.com";
		checkOK($from);
		
		if(mail($to, $subject, $message, $from)){
			echo "Message sent successfully.";
		}else{
			echo "Failed to send message.";
		}
	?>

TIA
Azlan

Posted: Sun Feb 19, 2006 4:10 am
by Benjamin
Try this:

Code: Select all

$from = "From: orders@email.com\n";

Posted: Sun Feb 19, 2006 4:11 am
by s.dot
try
"From: you@yourdomain.com\r\n";

Posted: Sun Feb 19, 2006 4:58 am
by Azlan
Thanks, but I am still having the same problem. Everything seems to work ok, but the mail is not received :?

Posted: Sun Feb 19, 2006 5:06 am
by s.dot
Well several questions come to mind.

Are you getting the message "mail not sent" or "mail sent ok"?

Are you receiving any email at all, even if it's a blank email?

What are you using to receive your email? Outlook? Hotmail? Yahoo? Perhaps you need additional email headers to verify yourself to that particular email service.

What type of email are you sending? You should specify at least the content type & charset of the email.

Is your SMTP server working?

Prepend this code to the top of your mail script

Code: Select all

ini_set("display_errors","on");
error_reporting(E_ALL);
Are you receiving any warnings?

Posted: Sun Feb 19, 2006 5:13 am
by Azlan
Thanks scrotaye. Problem solved finally. Seems I needed the rest of the headers.