Some question about Pear Mail

I get a Pear message of, “Validation failed for: My-Example.com" when $from = "My-Example.com <support@my-example.com>”. However, I don’t get an error if I change $from to "Example <support@my-example.com>" Why would having a hypen and a .com as part of the FROM address cause validation errors?

Also, is this the most efficient way to send out 500 emails or more at one time? I don’t know tons about SMTP, but I assume it is authenticating with the SMTP server for every single email that is being sent out with my DO WHILE loop.

Thoughts?


$from = "My-Example.com <support@my-example.com>";
$host = "mail.my-example.com";
$username = "support@my-example.com";
$password = "******";

$headers = array (
'To' => $recipient,
'From' => $from,
'Subject' => $subject,
'Reply-To' => $sender,
'Errors-To' => $sender);

$smtp = Mail::factory('smtp', array (
'host' => $host,
'auth' => true,
 'username' => $username,
'password' => $password));

$mail = $smtp->send($recipient, $headers, $body);

if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
$success = "Yes";
//Code for updating the DB table so the email doesn't get resent.
}

Hello? Still looking for some help.

I’ve got the same questions, although the question about repeated SMTP authentication is more or less elementary for me at the moment. The primary question, however, is immediate. I’m trying to send mail from “Daniel R. Ziegler <email@redacted.com>” and get “Validation failed for: Daniel R. Ziegler <email@redacted.com>”. Can anyone help sort this out? Is there a work-around or do I need to strip certain characters from the name?

A few hours later here and a solution. Change line 1 of your script to the following:


$from = "\\"My-Example.com\\" <support@my-example.com>";

And, for me at least, problem solved. This question must not come up frequently because it took a bit of digging to unearth it. Either everyone else using PEAR’s SMTP is a better programmer than I (likely) or it’s simply not a common usage.

Anyway, hopefully useful for someone in the future as this thread is the third or fourth result on Google for my initial search.