Hi there, I would like some help in resolving a problem with my
php-sent emails not being received by some accounts.
I'm sending an email out from a php page. The email is working to a
couple of accounts without a problem, but to some addresses, it just
isn't received. I investigate and i find that when i try to forward
the email from an account where the email was received, i see this at
the top.
----- Forwarded message from a@b.com -----
Date: 22 Oct 2004 17:08:07 -0000
From: a@b.com, UNEXPECTED_DATA_AFTER_ADDRESS@.SYNTAX-ERROR.
Reply-To: a@b.com, UNEXPECTED_DATA_AFTER_ADDRESS@.SYNTAX-ERROR.
Subject: Invoice from company name
To: a@b.com
I'm guessing that some email providers are rejecting the message based
on this. The script is below. Many thanks.
// Email Sending Start ---
$mailSubject = "Invoice from company name";
$mailHeader = "From:a@b.com <a@b.com>\r\nContent-type:
text/html";
$mailBody = "";
If ($fp = fopen("http://www.domain.com/invoice_view.php?id=".$id."&skipgranted=T",
"r")) {
while (!feof($fp)) { $mailBody .= fgets($fp, 20000); }
fclose($fp);
}
$result = mysql_query("SELECT email FROM clients WHERE id = $client_id");
if (mysql_num_rows($result) == 1) {
mysql_data_seek($result,0);
$data = mysql_fetch_object($result);
$mailTo = trim($data->email);
if (@mail($mailTo, $mailSubject, $mailBody, $mailHeader)) {
echo "The Invoice has been sent out to the client email address
".$mailTo." successfully !<br>"; } else {
echo "The Invoice failed to sent out !<br>";
}
} else {
echo "The client doesn't have any email account info !<br>";
}
// Email Sending End --- |
Request for Question Clarification by
palitoy-ga
on
25 Oct 2004 07:17 PDT
Hello apcs_uk-ga
I have a few ideas that may be causing this problem. To start with
can you please try the following for me and let me know if it solves
your problem?
Change this line:
$mailHeader = "From:a@b.com <a@b.com>\r\nContent-type: text/html";
To:
$mailHeader = "From:a@yourrealdomainname.com\r\nMIME-Version:
1.0\r\nContent-type: text/html; charset=iso-8859-1\r\n";";
The reasoning behind these changes are that each header should be
separated by \r\n (although some mail agents may work with a single
\n). Also your mailer *may* be checking the From: address is real,
b.com would not be a real domain name, and it may also not be able to
correctly parse the <a@b.com> part.
Let me know how this works (or not). Fingers crossed!
palitoy-ga
|
Clarification of Question by
apcs_uk-ga
on
25 Oct 2004 08:47 PDT
Thanks for the response, I will try this as soon as i get home from
work and let you know.
Fingers are crossed!
|
Clarification of Question by
apcs_uk-ga
on
25 Oct 2004 08:48 PDT
Oh and the a@b.com was only as an example for the purpose of GA (not
allowed to include my full email address). The script does include
genuine email addresses
|
Request for Question Clarification by
palitoy-ga
on
25 Oct 2004 09:13 PDT
I guessed the email address probably would be a false one but I wanted
to make sure. If this solution does not work let me know and I have a
few other ideas...
An alternate solution to this problem could be to utilise something such as:
http://phpmailer.sourceforge.net/
|
Clarification of Question by
apcs_uk-ga
on
26 Oct 2004 08:31 PDT
Hi, we tried your suggestion but get the same problem. We did move a
step closer, let's see what you think. We moved the database and the
php files to another server and it worked.
Here are the server info pages, perhaps you have some ideas? The PHP
versions are slightly different but would that cause this fault?
http://www.ppt68.com.my/email/phpinfo.php (this one works)
http://www.adamgough.com/phpinfo.php (this one doesn't)
|
Request for Question Clarification by
palitoy-ga
on
26 Oct 2004 09:11 PDT
Hi apcs_uk-ga
"PHP versions up to and including 4.2.2 contain vulnerabilities in the
mail()function allowing local script authors to bypass safe mode
restrictions and possibly allowing remote attackers to insert
arbitrary mail headers and content into the message."
http://www.yellowdoglinux.com/resources/errata/YDU-20021227-12.txt
I guess the first thing to notice is you are using a very old build of
PHP on the server that is not working. Is there any chance you could
upgrade this to something more modern?
Can you send any mail to multiple recipients using your script on the
server that does not work?
Can you send emails using this function on both servers?
function send_mail($myname, $myemail, $contactname, $contactemail,
$subject, $message) {
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\n";
$headers .= "X-Mailer: php\n";
$headers .= "From: \"".$myname."\" <".$myemail.">\n";
return(mail("\"".$contactname."\" <".$contactemail.">", $subject,
$message, $headers));
}
http://www.php.net/manual/en/function.mail.php
Did you try PHPMailer or is this not a suitable solution for you?
http://phpmailer.sourceforge.net/tutorial.html
Whilst troubleshooting this for you I found this good article on PHP's
mail() function:
http://www.devarticles.com/index2.php?option=content&task=view&id=309&pop=1&hide_ads=1&page=0&hide_js=1
|
Request for Question Clarification by
palitoy-ga
on
28 Oct 2004 01:30 PDT
Just checking to see whether you have got anywhere with this. Let me
know if you need any more help.
|
Clarification of Question by
apcs_uk-ga
on
28 Oct 2004 04:34 PDT
It does look as if it is the version of PHP but updating it isn't going to be easy.
Not the solution i was hoping for (and this might not even solve the
problem) but that's not your fault, and you've done all that you can,
for which i am grateful.
|
Clarification of Question by
apcs_uk-ga
on
28 Oct 2004 04:36 PDT
Um, i think you need to post an 'answer' for me to accept? I think?
|