postfix send email subject breaks the FROM - php

I am using postfix to send an email to the user, but the problem is it breaks the words where it finds the space.
Here is the screenshot:
postfix-send-email
PHP code to send an email:
<?php
$subject = "Status Of mail";
$message = "Test Email using Postfix Apache2";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: 'The Travel Worthy' 'pathik#gmail.com"\r\n";
$send = mail('test#yahoo.com', $subject, $message, $headers);
if($send)
{
return 1;
}
else
{
return 0;
}
?>

Try replacing
$headers .= 'From: 'The Travel Worthy' 'pathik#gmail.com"\r\n";
with
$headers .= "From: The Travel Worthy <pathik#gmail.com>\r\n";

Related

Send HTML Email using PHP - Not working when using email.2015#gmail.com?

I am using this basic php code to send out a html email.
When i use email#email.com as a to address the script works.
However, when i try to use email.2015#gmail.com the script says:
Parse error: syntax error, unexpected '#' in /home/u925912002/public_html/send_email.php on line 3
My code:
<?php
$to = ‘email.2015#gmail.com’;
$subject = 'I need to show html';
$from ='example#example.com';
$body = '<p style=color:red;>This text should be red</p>';
ini_set("sendmail_from", $from);
$headers = "From: " . $from . "\r\nReply-To: " . $from . "";
$headers .= "Content-type: text/html\r\n";
if (mail($to, $subject, $body, $headers)) {
echo("<p>Sent</p>");
} else {
echo("<p>Error...</p>");
}
?>
please can someone show me what i'm doing wrong. thanks
For your question recently closed: https://stackoverflow.com/questions/34106770/send-email-using-php-from-address-not-working
Try this:
$headers .= "From: Your Name <$from>\r\n";
and you can also add the 5th mail parameter:
mail($to, $subject, $body, $headers, '-finfo#userforum.com').
Works for me with these headers:
$from = "$name <$email>\r\n";
$to = "$username <$useremail>\r\n";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= "From: $name <$email>\r\n";
$headers .= "Reply-To: $name <$email>\r\n";
you are using Apostrophe(‘) instead of quotes(')
try this -
$to = 'email.2015#gmail.com';
instead of this -
$to = ‘email.2015#gmail.com’;

How to check if mail was send or not using php?

How to check if mail was send or not using php ?
I use this code for send email using php. It's work good.
But i want to check email send success or not, How can i do that ?
<?PHP
$to = "test#mail.com";
$subject = "test subject";
$message = "test message";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: SENDER <noreply#sender.com>' . "\r\n";
$headers .= 'Return-Path: return#sender.com' . "\r\n";
mail($to, $subject, $message, $headers, '-freturn#sender.com');
?>

PHP - Not receiving email from contact form

I am not receiving emails from this contact form, but the message seems to sending okay and it also redirects me to the sent page.
I don't have access to the server only via FTP.
PHP
<?php
$to = 'test#gmail.com';
$subject = $_POST['subject'];
$name = $_POST['name'];
$email = $_POST['email'];
$comment = $_POST['comment'];
$body = <<<EMAIL
<html>
<p><h3>Email Submited From Website.</h3></p>
<p><strong>Name:</strong> $name</p>
<p><strong>Email:</strong> $email</p>
<p><strong>Subject:</strong> $subject</p>
<p><strong>Message:</strong> $comment</p>
</html>
EMAIL;
// 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: test email' . "\r\n";
$headers .= 'From: <website#mt.co.uk>' . "\r\n";
//$headers .= 'Cc: noreply#example.com' . "\r\n";
//$headers .= 'Bcc: noreply#example.com' . "\r\n";
if ($_POST['submit']){
mail($to, $subject, $body, $headers);
header ("Location: message-sent.php");
die();
} else {
header ("Location: message-failed.php");
die();
}
?>
Check if mail is actually being sent:
if (mail($to, $subject, $body, $headers)===false) {
echo "Not sent!";
} else {
echo "Sent!";
}
Change this:
$headers .= 'To: test email' . "\r\n";
$headers .= 'From: <website#mt.co.uk>' . "\r\n";
To this:
$headers .= "To: $to <test email>\r\n";
$headers .= "From: website#mt.co.uk <website#mt.co.uk>\r\n";
Also, you need to sanitize the subject and body of the email so that the email arrives, but this will usually be reflected in the results after email() reports a success, in that case the email will bounce, go to the spambox, or simply be refused.
If your hosting provider doesn't have an email server, you could try to use a free email server and phpMailer. https://github.com/PHPMailer/PHPMailer

Add bold text in mail sender text

Here is the code:
$email_body = "You have received a new message. ".
" Here are the details:\n\n Name: $name \n Email: $email_address \n Message \n $message";
I want to add bold text to: "Name:", "Email:", and "Message"
I have tried using the "< b > name: < /b>" (without space of course), but it doesn´t work. I want the text to be bold when i receive the mail.
// 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";
$email_body = "You have received a new message. ".
" Here are the details:\n\n <strong>Name:</strong> $name \n <strong>Email:</strong> $email_address \n Message \n $message";
// Mail it
mail($to, $subject, $message, $headers);
You need To Set Header Content Type Like This:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
Here is Example ....
<?php
$to = 'recivermail#email.com';
$subject = 'Your Subject';
$from = 'sender#email.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";
// Create email headers
$headers .= 'From: '.$from."\r\n".
'Reply-To: '.$from."\r\n" .
'X-Mailer: PHP/' . phpversion();
// Compose a simple HTML email message
$message = '<html><body>';
$message .= '<h1 style="color:#f40;">Your Title</h1>';
$message .= '<b style="color:#080;font-size:18px;">How Are You?</b>';
$message .= '</body></html>';
// Sending email
if(mail($to, $subject, $message, $headers)){
echo 'Your mail has been sent successfully.';
} else{
echo 'Unable to send email. Please try again.';
}
?>

PHP Email sending BCC

I know there are a few similar questions to this but I just can't get it working.
Ok, I have a list of emails grabbed from my database in a variable called $emailList.
I can get my code to send an email from a form if I put the variable in the $to section but
I cannot get it to work with bcc. I've even added an email to the $to incase it was that but it doesn't make a difference.
Here is my code.
$to = "name#mydomain.com";
$subject .= "".$emailSubject."";
$headers .= 'Bcc: $emailList';
$headers = "From: no-reply#thepartyfinder.co.uk\r\n" . "X-Mailer: php";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = '<html><body>';
$message .= 'THE MESSAGE FROM THE FORM';
if (mail($to, $subject, $message, $headers)) {
$sent = "Your email was sent!";
} else {
$sent = ("Error sending email.");
}
I've tried both codes:
$headers .= 'Bcc: $emailList';
and
$headers .= 'Bcc: '.$emailList.';
It's not that the emails aren't separated because they are. I know they are because it works if I put $emailList in the $to section.
I Should add, ignore the $message bits and the HTML stuff. I've not provided all of that so that is why it's missing from this code.
You have $headers .= '...'; followed by $headers = '...';; the second line is overwriting the first.
Just put the $headers .= "Bcc: $emailList\r\n"; say after the Content-type line and it should be fine.
On a side note, the To is generally required; mail servers might mark your message as spam otherwise.
$headers = "From: no-reply#thepartyfinder.co.uk\r\n" .
"X-Mailer: php\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= "Bcc: $emailList\r\n";
You were setting BCC but then overwriting the variable with the FROM
$to = "name#mydomain.com";
$subject .= "".$emailSubject."";
$headers .= "Bcc: ".$emailList."\r\n";
$headers .= "From: no-reply#thepartyfinder.co.uk\r\n" .
"X-Mailer: php";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = '<html><body>';
$message .= 'THE MESSAGE FROM THE FORM';
if (mail($to, $subject, $message, $headers)) {
$sent = "Your email was sent!";
} else {
$sent = ("Error sending email.");
}

Categories