Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP mail() adding brackets in the from header

Tags:

php

sendmail

I'm trying to send the alter the from: header in my email to match the corporate email standard within my origination. But this involves putting the department of the system within curly brackets.

The email is successfully sent with the header but ignores the department text and brackets within the header.

-Is there a way I can output this header without the brackers being ignored?

 $emailBody = "content test";
 $subject = 'subject test';
 $message = "<html><body>".$emailBody."</body></html>";
 $headers = 'From: System (department) <[email protected]>' . "\r\n";
 $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

 $sendmail = mail('[email protected]',$subject,$message,$headers);

Output:

 From: System

Desired Output:

 From: System (department) 
like image 207
Orbitall Avatar asked Oct 21 '25 13:10

Orbitall


1 Answers

You need to use double quotes (") for name of user if you have spaces ( ) before <[email protected]>.

$headers = 'From: "System (department)" <[email protected]>' . "\r\n";

First email is your code without double quotes and second is my, with double quotes.

like image 169
doubleui Avatar answered Oct 23 '25 03:10

doubleui



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!