I'm getting this error Warning: mail() Multiple or Malformed new lines found in additional header... I have tried giving the $message variables a different variable name, but nothing I do works.
There error is coming from the last line that I posted in this..
mail($to,$subject,$message,$headers);
Full code
$to = $approved_email;
$subject = 'There is a new user request to join the ';
$message = '
<html>
<head>
<title>New User Request</title>
</head>
<body>
<p>Hi '.$approved_firstname.',</p><br>
<p>Your Account has been accepted. You have been added to the group. To sign in, click this link
http://example.com . </p><br>
<p>Thank you,</p>
<p>Administration</p>
</body>
</html>
';
$from = "user-requests#example.com";
$Bcc = "user-requests-confirm#example.com";
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: ' .$to. "\r\n";
$headers .= 'From: ' .$from. "\r\n";
$headers .= 'Bcc: '.$Bcc. "\r\n";
// Send the email
mail($to,$subject,$message,$headers);
I have a similar email in another file and it works. What could be the problem?
Related
I am trying to figure out how I can change what shows up for my company when I send out php emails. Right now this shows up:
I don't want it to say newsletter, I want it to say my companies name. I don't have anything in my code that says newsletter, so I am unsure of why that is even displaying, unless it just naturally takes what comes before the # in the email address. newsletter#companyname.com
What can I change in my code, so it reads my company name in the area I showed in the image, similar to what Amazon does, minus the .com.
$to = $newsletter_email;
$subject = 'Thank you for subscribing to the Newsletter';
$message = '
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Newsletter</title>
</head>
<body>
</body>
</html>
';
$from = "newsletter#companyname.com";
$Bcc = "newsletter-notification#companyname.com";
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: ' .$to. "\r\n";
$headers .= 'From: ' .$from. "\r\n";
$headers .= 'Bcc: '.$Bcc. "\r\n";
// Send the email
mail($to,$subject,$message,$headers);
Try
$from = 'My Company <newsletter#companyname.com>';
I think the problem is the way Gmail is displaying the name of the person when it's not specified.
Check what's in your sendmail.ini and php.ini:
sendmail.ini
force_sender=<email>
php.ini
sendmail_from=<email>
i have try to send mail with russian name but its not working on outlook but showing correctly on gmail.. how can i fix it.. it show like this
ÐоÑÑале [info#stackoverflow.com]
i have try following code $subject = mb_encode_mimeheader('Потцале',"UTF-8");
but after this gmail also show same problem.. russian character display well on the body section but not on header of mail.
here is my code..
<?php
// if the url field is empty
$emails='info#stackoverflow.com';
$email='xyz#gmail.com';
$con='Потцале Потцале Потцале Потцале';
$subject = mb_encode_mimeheader('Потцале',"UTF-8");
$msg='<html><head><meta http-equiv="Content-Type" content="text/html;
charset=utf-8" /></head><body>Потцале Потцале Потцале Потцале </body></html>';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .='Content-Transfer-Encoding: base64' . "\r\n";
$headers .= 'From:'.$subject.'<'.$emails.'> ' . "\r\n";
// then send the form to your email
$ash = #mail( $email,$con,$msg,$headers);
// #mail( $email,'Submit Form','Thanks For Contacting Us We Will Contact You Shortly',$headers);
if($ash)
{
echo 'send';
}
else
{
echo ' Not Send send';
}
?>
<html>
Thanks!
Thanks
We'll get back to you as soon as possible.
after subject.. please help me ..
I'm trying to test if the return-path will bounce back on my gmail, but not.
I'm testing to send it to my email (enalds#gmail.com): it works!
And send to unknown email (gifjgogsdkg#fafasfsa.com): it didn't bounce back.
Here's my code
<?php
$message = '
<html>
<head>
<title>Sample Email</title>
</head>
<body>
Sample Email
<br /><br />
Click here to Unsubscribe
</body>
</html>
';
$sender = "enalds#gmail.com";
$email_address = "sender_name#yahoo.com";
$subject = "Testing Email";
$template_name = "Sample Email";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'Return-Path: enalds#gmail.com' . "\r\n";
$headers .= 'From: '.$sender.'' . "\r\n";
if(mail($email_address, $subject, $message, $headers, '-fenalds#gmail.com'))
echo "{$i}. {$email_address} - <span style='color:green'>Successfully</span> Sent [{$template_name}]<br />";
else
echo "{$i}. {$email_address} - <span style='color:green'>Unsuccessfully</span> Sent [{$template_name}]<br />";
You have two solutions to this issue:
First one is leave blank in the php.ini configuration file the "sendmail_from" variable.
This way you could add the additional parameters in the mail function like you have in your code.
The second approach, is set "sendmail_from" in php.ini if you want to have always the same "Return-Path" for every email.
I have the following issue when using php mail, I'll expose the two ways I do it and wich result I get and expect:
Case 1:
$to = $EmailsPropiosPresupuestos;
$subject = $txtAsuntoCliente;
$message = $emailCliente;
$headers .= "From: noreply\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
The email i sent and the html decoded in the correct way, but my "From" header looks like: "noreply#124512.net" (Strange root).
Case 2:
$to = $EmailsPropiosPresupuestos;
$subject = $txtAsuntoCliente;
$message = $emailCliente;
$headers .= "From: noreply#example.com\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
Now my "From" header is fine, "noreply#example.com", but the mail doesn't decode the html, so I can't view the message in the correct way.
Try to add the MIME version to your header:
$headers .= "MIME-Version: 1.0\n";
For the no-reply I suggest you to add it using the Reply-To:
$headers .= "Reply-To: noreply#example.com\n";
This will allow you to keep a better from email address.
And In my code I use \n on each header line and finish with \r\n.
from: http://de3.php.net/manual/en/function.mail.php
Example #4 Sending HTML email
It is also possible to send HTML email with mail().
<?php
// multiple recipients
$to = 'aidan#example.com' . ', '; // note the comma
$to .= 'wez#example.com';
// subject
$subject = 'Birthday Reminders for August';
// message
$message = '
<html>
<head>
<title>Birthday Reminders for August</title>
</head>
<body>
<p>Here are the birthdays upcoming in August!</p>
<table>
<tr>
<th>Person</th><th>Day</th><th>Month</th><th>Year</th>
</tr>
<tr>
<td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
</tr>
<tr>
<td>Sally</td><td>17th</td><td>August</td><td>1973</td>
</tr>
</table>
</body>
</html>
';
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: Mary <mary#example.com>, Kelly <kelly#example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday#example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive#example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck#example.com' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
?>
$subject = 'Test';
$body = '<html>
<head>
<title>Birthday Reminders for August</title>
</head>
<body>
Test
</body>
</html>';
$headers = 'MIME-Version: 1.0' . '\r\n';
$headers .= 'Content-type: text/html; charset=iso-8859-1' . '\r\n';
$headers .= 'From: Lance <support#lancenewman.me>' . '\r\n';
$headers .= 'To: User <email#me.com>' . '\r\n';
//echo $headers;
mail('myemail#me.com', $subject, $body, $headers)or die('error');
The email gets sent but the to and from headers aren't showing up correctly. Gmail says that the email is send to my email, but not my name (Lance) like it's supposed to. The same is true for the from header. Also, all of the html tags are showing up in the email.
Any ideas?
I believe it has to do with '\r\n' being in single quotes instead of double quotes, like "\r\n", so it's not being evaluated, just a String Literal.