PDA

View Full Version : why cannot send email if recipient is ABC<abc@abc.com>


chleng
02-06-2006, 10:04 AM
Hi,

I'm now running Windows XP

my script


echo "<html><body>";

$recipient = "ABC mail<"."abc@abc.com".">";
$subject = "Testing the mail function";
$message = "Hello!\n\nThis is the body of the message.\n\n";
//$extra = "From: kris@phpworld.com\r\nReply-To: karn@nucleus.com\r\n";
$header = "From: Kris <kris@phpworld.com>";

$status =mail ($recipient, $subject, $message, $header);

if ($status === false)
{
echo "Mail is not accepted for delivery!";
}

echo "Sending mail...";
echo "</body></html>";




Error that display

Warning: mail() [function.mail]: SMTP server response: 501 <ABC Mail<abc@abc.com>>: "@" or "." expected after "ABC" in D:\wwwroot\osmslife\osmslife\Store\mail07.php on line 11
Mail is not accepted for delivery!Sending mail...



but when I change $recipient


echo "<html><body>";

$recipient = "abc@abc.com";
$subject = "Testing the mail function";
$message = "Hello!\n\nThis is the body of the message.\n\n";
//$extra = "From: kris@phpworld.com\r\nReply-To: karn@nucleus.com\r\n";
$header = "From: Kris <kris@phpworld.com>";

$status =mail ($recipient, $subject, $message, $header);

if ($status === false)
{
echo "Mail is not accepted for delivery!";
}

echo "Sending mail...";
echo "</body></html>";




it works. why is this so? any solution? program error or setting error? thanks!

Note: I've changed email to prevent spam robots from detecting emails. Please change it accordingly

Squid
02-06-2006, 10:17 AM
I'm not excactly sure but I don't think it sends the email since:

$recipient = "ABC mail<"."abc@abc.com".">";

Is not a valid e-mail address, abc@abc.com is.

Correct me if I'm wrong, I'm a newbie.

chleng
02-06-2006, 10:53 AM
$recipient will eventually evaluate to ABC<abc@abc.com>.

Would really appreciate if someone tells me what is wrong.

degsy
02-06-2006, 01:47 PM
You probably have white space at the end of the line.
Also, you don't need to break in & out

try this

$recipient = "ABC mail <abc@abc.com>\n";

chleng
02-07-2006, 01:29 AM
Hi,

it's still the same old thing that happen. thanks. I've use Editplus and enable the view tabs and spaces and line breaks.

regards

VBAssassin
02-07-2006, 03:34 AM
its because you dont put the <> naming stuff in the "to" part fo the email function... only a valid email address is for the "to" part.. the added <> goes in as a header like this:


$name = 'Scott Thompson';
$email_address = 'abc@abc.com';
$header = "From: \"" . $name . "\" <" . $email_address . ">" . "\r\n" . 'X-Mailer: PHP/';
mail('abc@abc.com', 'subject', 'content', $header) or die('couldnt send email');


thats what works for me :-D

degsy
02-07-2006, 04:14 PM
its because you dont put the <> naming stuff in the to part fo the email function... only a valid email address is for the "to" part.. the added <> goes in as a header like this:


http://uk.php.net/function.mail

Parameters


to
Receiver, or receivers of the mail.

The formatting of this string must comply with RFC 2822. Some examples are:


user@example.com
user@example.com, anotheruser@example.com
User <user@example.com>
User <user@example.com>, Another User <anotheruser@example.com>

VBAssassin
02-08-2006, 01:43 AM
@degsy

just wondering, whyd you quote my post exactly :confused: ?

best regards,
scott

VBAssassin
02-08-2006, 01:46 AM
@degsy

just wondering, whyd you quote my post exactly :confused: ?

best regards,
scott

oh never mind... i see why now lol. Well try it the way i suggested if the other way doesnt work lol... and see if any of them ways work? Theres obviously more than one way lol... learn somin new every day ay!!!

chleng
02-10-2006, 01:41 AM
When I follow your advice, of placing abc <abc@abc.com> into the headers and run it on linux server,

The email appears like the following

abc@abc.com; abc



$recipient = trim($abc_email);
$headers ="From: ".$sendingemails['FromPerson']."<".$sendingemails['FromEmail'].">\n";
$headers .= "To: $fullname <".trim($abc_email).">";


could it due to configurations in php.ini file? Or could it be due to different operating system? If so how do detect the operating system in which the script is running on?

thanks.

degsy
02-10-2006, 02:33 PM
phpinfo will give you your server info.