943,852 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 1019
  • PHP RSS
Nov 24th, 2008
0

php e-mail problem

Expand Post »
I have some simple php code. It worked fine on the old server, but now I am getting an error on the new server. Both former and present servers are Linux.

php Syntax (Toggle Plain Text)
  1. <?php
  2. function ConfirmationEmail ()
  3. {
  4. $from = "mo@abc.com";
  5. $recipient = "bill@yahoo.com";
  6. $cc1 = $from;
  7. $cc2 = "mo@gmail.com";
  8. $subject = "Trial e-mail!";
  9. $message = "This is a test!\n";
  10. $headers = "From: " . $from . "\r\n" . "Cc: " . $cc1 . " " . $cc2;
  11.  
  12. $success = mail($recipient,$subject,$message,$headers);
  13.  
  14. if ($success)
  15. echo "<br>A confirmation e-mail was just sent to you.<br>";
  16. else
  17. {
  18. echo "An attempt was made to send you an e-mail, ";
  19. echo "but it was unsuccessful. <br>";
  20. }
  21. }
  22. ?>

Here is my error message that I get from the mail server in an e-mail. Subject line is
Quote ...
"Inbox: Mail failure - malformed recipient address"
Quote ...
A message that you sent contained one or more recipient addresses that were
incorrectly constructed:

mo@abc.com mo@gmail.com: malformed address: mo@gmail.com may not follow mo@abc.com

This address has been ignored. The other addresses in the message were
syntactically valid and have been passed on for an attempt at delivery.
The e-mail addresses have been changed. The second address of the cc line is getting tossed out (mo@gmail.com). I'm not sure why. The recipient and the first cc address are being sent correctly. It worked on the last server. Any ideas? Thanks.
Similar Threads
Featured Poster
Reputation Points: 2614
Solved Threads: 687
Posting Expert
VernonDozier is offline Offline
5,375 posts
since Jan 2008
Nov 24th, 2008
0
Re: php e-mail problem
i made an email class. try it and make sure that you have the headers formed correctly.

http://www.daniweb.com/forums/thread155761.html - Post
#12

then we will see if something is wrong the the server config.
Last edited by kkeith29; Nov 24th, 2008 at 4:22 pm.
Reputation Points: 235
Solved Threads: 193
Nearly a Posting Virtuoso
kkeith29 is offline Offline
1,315 posts
since Jun 2007
Nov 24th, 2008
0

Re: php e-mail problem

Click to Expand / Collapse  Quote originally posted by kkeith29 ...
i made an email class. try it and make sure that you have the headers formed correctly.

http://www.daniweb.com/forums/thread155761.html - Post
#12

then we will see if something is wrong the the server config.
Hey, thanks! I think I can make use of this. On my first try, it only did the first cc address but not the second, same as with mine, but I'll play around with it. It did send the e-mail to the first cc address. I could be using it wrong. I'll try it more carefully and get back to you. It could come in handy with the ability to send attachments, html, etc. I haven't tried those out yet.

As far as my problem goes, I did an experiment and if I change line 10 from:

PHP Syntax (Toggle Plain Text)
  1. $headers = "From: " . $from . "\r\n" . "Cc: " . $cc1 . " " . $cc2;

to

$headers = "From: " . $from . "\r\n" . "Cc: " . $cc1 . ", " . $cc2;

Note the added comma above. It seems to work better. Are you supposed to separate the addresses with a comma? I'll get back to you regarding your e-mail class. That could have great potential. Thank you!
Featured Poster
Reputation Points: 2614
Solved Threads: 687
Posting Expert
VernonDozier is offline Offline
5,375 posts
since Jan 2008
Nov 25th, 2008
0

Re: php e-mail problem

Hi,

This may be way off the mark, but have you tried adding a comma between $cc1 and $cc2??

Hence,
PHP Syntax (Toggle Plain Text)
  1. $headers = "From: " . $from . "\r\n" . "Cc: " . $cc1 . ", " . $cc2;

That may be why the gmail address is not allowed to follow the abc address.

Best,

Rob.
Reputation Points: 101
Solved Threads: 74
Posting Pro in Training
blocblue is offline Offline
427 posts
since Jan 2008
Nov 29th, 2008
0

Re: php e-mail problem

Click to Expand / Collapse  Quote originally posted by robothy ...
Hi,

This may be way off the mark, but have you tried adding a comma between $cc1 and $cc2??

Hence,
PHP Syntax (Toggle Plain Text)
  1. $headers = "From: " . $from . "\r\n" . "Cc: " . $cc1 . ", " . $cc2;

That may be why the gmail address is not allowed to follow the abc address.

Best,

Rob.
Yes, that was the problem. Thanks to both of you.
Featured Poster
Reputation Points: 2614
Solved Threads: 687
Posting Expert
VernonDozier is offline Offline
5,375 posts
since Jan 2008
Nov 30th, 2008
0

Re: php e-mail problem

No problem, and one last thing to tidy the line of code up...

PHP Syntax (Toggle Plain Text)
  1. $headers = "From: $from\r\nCc: $cc1, $cc2";

You don't need to concatenate if the variables are enclosed within double quotes, although being a postaholic, I expect you know this

A matter of personal preference I suppose.

R.
Reputation Points: 101
Solved Threads: 74
Posting Pro in Training
blocblue is offline Offline
427 posts
since Jan 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: backup from MySQL database
Next Thread in PHP Forum Timeline: Running PHP files without .php extension





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC