user1395625
user1395625

Reputation: 25

in php mail function Can we set From attribute as a Word Not Email?

In php Mail Function, when we send headers, can we set the "From Mail" to be a Word like "Company Newsletter" Only, not in an email form as [email protected] ?? how can we do that ? because writing it is (not in an email form) prevents the email from being sent.

here's my code:

  $headers  = "MIME-Version: 1.0\r\n";
  $headers .= "Content-type: text/html; charset=windows-1256\r\n";

i have tried what tim suggested , having

  $row['SenderMail'] =  "Company Newsletter <[email protected]>";
  $headers .= "From:".$row['SenderMail']."\r\n"; 

  $subject=str_replace('%26','&',$row['Subject']);

  @mail($row['DestinationMail'], $subject, $row['Body'],$headers);

But still email isn't being sent.any help ?

Upvotes: 0

Views: 525

Answers (3)

Laurent Brieu
Laurent Brieu

Reputation: 3367

I've just rechecked and it's working with a basic example like :

$headers = 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=windows-1256'."\r\n"; 
$headers .= 'To: Test <[email protected]>'."\r\n"; 
$headers .= 'From: Company Test <[email protected]>'."\r\n"; 

mail('Test <[email protected]>', 'test mail', 'test content', $headers);

Under which PHP version are you ? Did you configure your mail server ? Can you please put these lines in top of your script :

ini_set('display_errors', 'On');
error_reporting(E_ALL | E_STRICT); 

Upvotes: 0

Laurent Brieu
Laurent Brieu

Reputation: 3367

Please use the following :

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=windows-1256'."\r\n";
$headers .= 'To: '.$row['SenderMail'].' <'.$row['SenderMail'].'>'."\r\n";
$headers .= 'From: Company Newsletter <[email protected]>'."\r\n";

mail($row['DestinationMail'], $subject, $row['Body'], $headers);

That should do the trick !

Upvotes: 0

Tim
Tim

Reputation: 8606

The following is a valid From: header - note the address is in angle brackets:

"Company Newsletter <[email protected]>"

Many email clients will simply show the Company Newsletter in the From column of the interface.

Note that this is not allowed in the Return-Path: header, just the From:

Note 'display name' in RFC 2822 3.4 https://www.rfc-editor.org/rfc/rfc2822#section-3.4

Upvotes: 2

Related Questions