php mail function help needed

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Azlan
Forum Newbie
Posts: 3
Joined: Sun Feb 19, 2006 3:55 am

php mail function help needed

Post 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
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Try this:

Code: Select all

$from = "From: orders@email.com\n";
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

try
"From: you@yourdomain.com\r\n";
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Azlan
Forum Newbie
Posts: 3
Joined: Sun Feb 19, 2006 3:55 am

Post by Azlan »

Thanks, but I am still having the same problem. Everything seems to work ok, but the mail is not received :?
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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?
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Azlan
Forum Newbie
Posts: 3
Joined: Sun Feb 19, 2006 3:55 am

Post by Azlan »

Thanks scrotaye. Problem solved finally. Seems I needed the rest of the headers.
Post Reply