Getting an image/logo to appear in a php email - php

I am trying to add my companies logo inside of a php email that I will be sending out to customers after they order. However, it is not working. The actual link to my image is a public url.
What am I doing wrong?
$logoImage = 'https://example.com/images/BFBlogo1.gif';
// Prepare the Email
$to = $email;
$subject = 'Your Example order'. $AuthorrizeResponseText; transaction Id or invoice #, however you set it up as.
$message = '<img src="'.$logoImage.'">';
$message = 'Thank you for ordering with us! ';
$from = "auto-confirm#example.com";
$cc = "order-receipts#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 .= 'Cc: '.$cc. "\r\n";
// Send the email
mail($to,$subject,$message,$headers);
My second attempt:
$message = '<img src="'.$logoImage.'">';
$message .= 'Thank you for ordering with us! ';

You forgot to concate:
$message = '<img src="'.$logoImage.'">';
$message = 'Thank you for ordering with us! '; // here $message is overwrtting.
Should be like this:
$message = '<img src="'.$logoImage.'">';
$message .= 'Thank you for ordering with us! ';
Update
logoImage = 'https://example.com/images/BFBlogo1.gif';
// Prepare the Email
$to = $email;
$subject = 'Your Example order'. $AuthorrizeResponseText;
$message = '<img src="'.$logoImage.'">';
$message .= 'Thank you for ordering with us! ';
$from = "auto-confirm#example.com";
$cc = "order-receipts#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 .= 'Cc: '.$cc. "\r\n";
// Send the email
mail($to,$subject,$message,$headers);

You set the image tag:
$message = '<img src="'.$logoImage.'">';
But then on the very next line you overwrite it:
$message = 'Thank you for ordering with us! ';
Maybe you meant to concatenate instead?:
$message .= 'Thank you for ordering with us! ';
Please note also that if nearly the entire body of the message is an image then I wouldn't be at all surprised if the mail is treated as spam by almost any system that looks at it.

Related

send html template in php

My Php mail code is like this i want to send html content in mail but i can not send html template with this code
$to = $email;;
$subject = 'New Order Detail';
$message = 'Hi Jane';
$from = 'info#abc.co.in';
// Sending email
if(mail($to, $subject, $message))
{
echo 'Your mail has been sent successfully.';
}
else
{
echo 'Unable to send email. Please try again.';
$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 = '<table border="1" align="center" width="50%">';
$message .= '<tr><td>Test Mail';
$message .= '</td></tr>';
//$message .= '<p style="color:#080;font-size:18px;">Will you marry me?</p>';
$message .= '</table>';
$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.';
}
}
This kind of output i get in mail i do not know where is my mistake in this code..
Output
<html><body>
<table border="1" align="center" width="50%">
<tr><td>Test Mail</td></tr>
</table>
</body></html>
There are some errors in your code and also wrong if statement I would like to recommend following script to you for sending email.
$to = $email;
$subject = 'New Order Detail';
$message_text = 'Hi Jane';
$from = 'info#abc.co.in';
$from_name = 'John';
$to_name = 'Smith';
// Sending email
if(!empty($to) && !empty($message_text ))
{
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Create email headers
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: ' . ucwords($to_name) .' <'.$to.'>' . "\r\n";
$headers .= 'From: ' . ucwords($from_name) . ' <'. $from. '>' ."\r\n";
// Compose a simple HTML email message
$message = '<html><body>';
$message = '<table border="1" align="center" width="50%">';
$message .= '<tr><td>Test Mail';
$message .= '</td></tr>';
$message .= '<p style="color:#080;font-size:18px;">'.$message_text .'</p>';
$message .= '</table>';
$message .= '</body></html>';
// Sending email
mail($to, $subject, $message, $headers);
echo 'Your mail has been sent successfully.';
}else{
echo 'Unable to send email. Please try again.';
}
add proper header contents.
// Compose a simple HTML email message
$message = '<html><body>';
$message = '<table border="1" align="center" width="50%">';
$message .= '<tr><td>Test Mail';
$message .= '</td></tr>';
//$message .= '<p style="color:#080;font-size:18px;">Will you marry me?</p>';
$message .= '</table>';
$message .= '</body></html>';
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: text/html; charset=iso-8859-1';
// Additional headers
$headers[] = 'To: abc <abc#example.com>, xyz <xyz#example.com>';
$headers[] = 'From: ABC <Abc#example.com>';
$headers[] = 'Cc: abc#example.com';
$headers[] = 'Bcc: xyz#example.com';
// Mail it
mail($to, $subject, $message, implode("\r\n", $headers));
Set your character set to UTF-8:
$headers .= "Content-type:text/ html;charset=UTF-8" . "\r\n";
That should fix it.
A variation on a theme perhaps and redundant as you have an answer. You should be able to add styles within the style tag region of the below code - or you could potentially add a link to an external css file but that could cause issues.
$to = $email;
$subject = 'New Order Detail';
$message = 'Hi Jane';
$from = 'info#abc.co.in';
$obj=new StdClass;
$obj->success='Your mail has been sent successfully.';
$obj->fail='Unable to send email. Please try again.';
$obj->nl="\r\n";
$status = #mail( $to, $subject, $message );
if( $status ) {
exit( $obj->success );
} else {
$headers = array();
$html = array();
$headers[]="MIME-Version: 1.0";
$headers[]="From: {$from}";
$headers[]="Reply-To: {$from}";
$headers[]="X-Mailer: PHP/". phpversion();
$headers[]="MIME-Version: 1.0";
$headers[]="Content-type: text/html; charset=iso-8859-1";
$html[]="";
$html[]="<html>";
$html[]="<head>";
$html[]="<title>{$subject}</title>";
$html[]="<style>";
$html[]="p{color:red;font-size:18px;}";
$html[]="table{border:1px solid black;width:50%;display:table;}";
$html[]="td{text-align:center;background:yellow;color:blue;}";
$html[]="</style>";
$html[]="</head>";
$html[]="<body>";
$html[]="<table>";
$html[]="<tr><td>Test Mail</td></tr>";
$html[]="<tr><td><p>Will you marry me?</p></td></tr>";
$html[]="</table>";
$html[]="</body>";
$html[]="</html>";
$status = #mail( $to, $subject, implode( $obj->nl, $html ), implode( $obj->nl, $headers ) );
exit( $status ? $obj->success : $obj->fail );
}

postfix send email subject breaks the FROM

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";

how to change the from attribute to my email in mail() function

I am trying to send an email to my customers when they place an order on my website. But the from appears like this:
From : n9da2313
I need to exchange it with info#awraq.me
I tried this but didn't work
`
$to = "founder#awraq.me";
$subject = "Your order";
$message = "Your order was placed successfuly";
$headers = "From: info#awraq.me";
$headers .= "\r\nReply-To: info#awraq.me";
$headers .= "\r\nX-Mailer: PHP/".phpversion();
mail($to,$subject,$message,$headers,"-f info#awraq.me");
`
try this-
$to = "somebody#example.com, somebodyelse#example.com";
$subject = "HTML email";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// More headers
$headers .= 'From: <webmaster#example.com>' . "\r\n";
$headers .= 'Cc: myboss#example.com' . "\r\n";
mail($to,$subject,$message,$headers);
If its not working then check if you have done some configuration in php.ini file.

PHP processing form : unknown sender

I created a form with a processing PHP file. Everything works fine. I receive the mail but it's from "Unknow sender" in Gmail. Why please ?
I would like to see in my email box the name and the firstname of the person who fills the form. What's wrong in my code ?
<?php
if(isset($_POST) && isset($_POST['form3_firstname']) && isset($_POST['form3_name']) && isset($_POST['form3_email']) && isset($_POST['form3_telephone']) && isset($_POST['form3_message'])) {
extract($_POST);
if(!empty($form3_firstname) && !empty($form3_name) && !empty($form3_email) && !empty($form3_telephone) && !empty($form3_message)) {
$to = 'XXXXXX#gmail.com'; // My real email
$subject = 'Contact from the site';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-Type: text/html; charset=UTF-8' . "\r\n";
$headers .= 'From:' .$form3_firstname. " " .$form3_name. "\r\n";
$headers .= 'Reply-To:'.$form3_email. "\r\n";
$message = '<html><body>';
$message .= '<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>';
$message .= '<table>';
$message .= '<tr><td colspan="2"><p>MESSAGE</p></td></tr>';
$message .= '<tr><td>Firstname :</td><td>'.$form3_firstname.'</td></tr>';
$message .= '<tr><td>Name :</td><td>'.$form3_name.'</td></tr>';
$message .= '<tr><td>Email :</td><td>'.$form3_email.'</td></tr>';
$message .= '<tr><td>Telephone :</td><td>'.$form3_telephone.'</td></tr>';
$message .= '<tr><td>Message :</td<td>'.stripslashes($form3_message).'</td></tr>';
$message .= '</table>';
$message .= '</body></html>';
if(mail($to, $subject, $message, $headers)){
echo "Form sent";
} else {
echo "Form not sent";
}
} else {
echo "You have not filled in the field";
}
}
?>
Replace the $form3_name with $form3_email
$headers .= 'From:' .$form3_firstname. " " .$form3_name. "\r\n";
^^^^^^^^^^^^ //<----- Here
That's a name , not an email address , and that's the reason you get that error.
Also, you need to wrap them in tags <>
The right way..
$headers .= 'From:' .$form3_firstname. " ".'<'.$form3_email.'>'."\r\n";
replace "\r\n" with "\n" and your problem will be solved... and also put return-path in your headers...
$headers = 'MIME-Version: 1.0' . "\n";
$headers .= 'Content-Type: text/html; charset=UTF-8' . "\n";
$headers .= 'From: \''.$form3_firstname.'\' <'.$form3_firstname.'>\r\nReturn-Path: <'.$form3_firstname.'>
$headers .= 'From:' .$form3_firstname. " " .$form3_name. "\n";
$headers .= 'Reply-To:'.$form3_email. "\n";
please let me know if you want furtther guidance...
Because you do not supply an emailaddress in your "From:" header. There always needs to be an emailaddress.
Try something like:
$headers .= "From: $form3_firstname $form3_name <$form_email>\r\n";
Mind you, you may have to test and/or escape your form variables; for instance, check that there is no newline in there, otherwise your form might be abused for spamming.

Getting a CC copy of user invite Emails

The code below works great. It allows a user to send a recommendation for my site to a list of friends via email.
For each person that gets the email below, I would like to get an email with that person's email, and the name of the person that sent them the message. If my email address was john#site.com, what code could I use to do this?
Thanks in advance,
John
$msg = "<html><body>Hello, your friend ".htmlspecialchars($_POST['sendername'])." recommends that you use <a href='http://www.site.com/'>Site.com</a>.<a href='http://www.site.com/'>Site.com</a><br><br><img src='http://site.com/images/blacklogo.PNG'></body></html>";
$subject = "Try out Site.com";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: ' . $_POST['sendername'] . "\r\n";
foreach($_POST['email'] as $email){
mail($email, $subject,$msg,$headers);
}
$msg = "<html><body>Hello, your friend ".htmlspecialchars($_POST['sendername'])." recommends that you use <a href='http://www.site.com/'>Site.com</a>.<a href='http://www.site.com/'>Site.com</a><br><br><img src='http://site.com/images/blacklogo.PNG'></body></html>";
$subject = "Try out Site.com";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "CC: foo#example.com\r\n";
$headers .= "BCC: foo#example.com\r\n";
$headers .= 'From: ' . $_POST['sendername'] . "\r\n";
foreach($_POST['email'] as $email){
mail($email, $subject,$msg,$headers);
}
Rather than messing about with raw headers, consider using one of the many great APIs available, like Swiftmailer, PHPMailer, or Zend_Mail to name just three. Zend_Mail example:
$mail = new Zend_Mail();
$mail->setBodyHtml('<p>hello</p>');
$mail->setFrom('foo#example.com', 'foo#example.com');
$mail->setSubject('Test Subject');
$mail->addTo('foo#example.com', 'Test');
$mail->addCc('foo#example.com', 'Another Test');
$mail->addBcc('foo#example.com', 'Another Test');
$mail->send();

Categories