Connecting Tech Pros Worldwide Forums | Help | Site Map

php mail- headers

Member
 
Join Date: Mar 2008
Location: India
Posts: 100
#1: Jun 12 '09
hi

i m sending mail using php mail().

while adding headers i m adding the email id in the header dynamically.,
Expand|Select|Wrap|Line Numbers
  1. <?
  2. //static value is passed
  3. $header ="From: ".$fname." <example@example.com>\r\n";
  4.  
  5.  
  6. //output when header is printed i get
  7. From: vijay <example@example.com>
  8.  
  9.  
  10. //but when dynamically passed
  11. $header ="From: ".$fname." <".$agentmailid.">\r\n";
  12.  
  13. //output when header is printed i get
  14. From: vijay 
  15.  
  16.  
  17.  
  18. ?>
  19.  
why does the mail id not getting displayed when passed through an variable..


regards
vijay

prabirchoudhury's Avatar
Familiar Sight
 
Join Date: May 2009
Location: Wellington, New Zealand
Posts: 152
#2: Jun 12 '09

re: php mail- headers


hey

1. you might have have a problem with "$agentmailid" variable. coz your header is giving me From: Name[example_from id]

2. could try with the code below

Expand|Select|Wrap|Line Numbers
  1.  
  2. those are the example of normal php mail()  function variables..
  3. $to = "example_to@xxx.co.nz";
  4. $subject = "Test mail";
  5. $message = "Hello ! This is a simple email message frm Vijay.";
  6. $from_mail = "example_from@xxx.co.nz";
  7.  
  8. //or could use
  9. $from_mail = $agentmailid;
  10. $from = $fname."<$from_mail>\r\n";
  11. $header = "From: $from";
  12. mail($to,$subject,$message,$header);
  13.  
  14.  
:)
Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,754
#3: Jun 12 '09

re: php mail- headers


As usually, I recommend using PHPMailer to send emails.
It takes care of all this kind of stuff for you.
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,949
#4: Jun 12 '09

re: php mail- headers


Quote:

Originally Posted by Atli View Post

As usually, I recommend using PHPMailer to send emails.
It takes care of all this kind of stuff for you.

SwiftMailer! SwiftMailer! SwiftMailer!
Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,754
#5: Jun 12 '09

re: php mail- headers


Quote:

Originally Posted by Markus View Post

SwiftMailer! SwiftMailer! SwiftMailer!

Or that. Same thing, different packaging :P

I do like the way SwitfMailer returns $this, allowing you to stack method calls.
Not sure PHPMailer does that to.
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,949
#6: Jun 12 '09

re: php mail- headers


Quote:

Originally Posted by Atli View Post

Or that. Same thing, different packaging :P

I do like the way SwitfMailer returns $this, allowing you to stack method calls.
Not sure PHPMailer does that to.

Gotta love method chaining :D

SwiftMailer seems much more professional, tbh. Pretty complex too; very well written.
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,662
#7: Jun 12 '09

re: php mail- headers


Quote:

Originally Posted by Markus View Post

SwiftMailer seems much more professional, tbh. Pretty complex too; very well written.

gotta agree with that, my favourite is sending customizable batch mails.
Reply