PHP email shows html source code in Apple Mail - php

I am sending an html email and the email shows perfectly fine everywhere except it shows the source code instead of the content in Apple mail.
Here is what I've done:
$to = "";
$subject = "";
$message = '
<html>
<head>
<title>New Inquiry From Quick Contact Form</title>
</head>
<body>
<table border="0" width="100%" cellspacing="0" cellpadding="0" bgcolor="#F4F3F4">
<tbody>
<tr>
<td style="padding: 15px;">Name:</td>
</tr>
<tr>
<td style="padding: 15px;">Last Name:</td>
</tr>
</tbody>
</table>
</body>
</html>
';
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= 'From: "<support#mydomain>"' . "\r\n";
mail($to,$subject,$message,$headers);
Note: The HTML in my "message" variable above is just sample. I have a valid HTML in my actual development. I think I am doing something wrong with my headers.
Any help is highly appreciated!
Thanks,

Not sure, it it will help, but I would try to use phpmailer class, as it makes headers more accurate (google for download phpmailer class).
Also you can send e-mails using g-mail smtp server (google for php send email through gmail).

Related

image is not embeding in email in php

I am trying to embed the image to the html content of email in php but whenever the email sent it show me broken link of image there. Image is not embeding to the email here is the code
<?php
$to = 'xxxx#xxxx.com';
$subject = "Beautiful HTML Email using PHP by CodexWorld";
$htmlContent = '
<html>
<head>
<title>Welcome to CodexWorld</title>
</head>
<body>
<h1>Thanks you for joining with us!</h1>
<table cellspacing="0" style="border: 2px dashed #FB4314; width: 300px; height: 200px;">
<tr>
<th>Name:</th><td>CodexWorld</td>
</tr>
<tr style="background-color: #e0e0e0;">
<th>Email:</th><td>contact#codexworld.com</td>
</tr>
<tr>
<th>Website:</th><td>www.codexworld.com</td>
</tr>
<tr>
<th>image:</th><td><img src="http://xxxxxxxxxxxxx.com/email/1.png"/></td>
</tr>
</table>
</body>
</html>';
// Set content-type header for sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// Additional headers
$headers .= 'From: xxxx#xxxxx.com' . "\r\n";
// Send email
if(mail($to,$subject,$htmlContent,$headers)):
$successMsg = 'Email has sent successfully.';
else:
$errorMsg = 'Email sending fail.';
endif;
?>
Please guide me where is I am wrong

Sending email with PHP, Gmail doesn't work

When I try to send my mail via php, GMail does not accept my html:
Simple example:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body style="padding:0px; margin:0PX;" bgcolor="#dfdfdf">
<table width="100%" align="center" border="0" cellpadding="0" cellspacing="0" bgcolor="" style="table-layout:fixed; margin:0 auto;">
<tr>
<td width="640" align="center" valign="top">
Screenshot: <img src="data:image/jpeg;base64,someimginfo" />
</td>
</tr>
</table>
</body>
</html>
GMail output:
Gmail edits my text e.g. <html> --> "<html>"
The headers I use: MIME-Version: 1.0 & Content-type: text/html; charset=UTF-8
What am I doing wrong?
EDIT PHP Code:
<?php
$recipient = "xxxxxx#gmail.com";
$image = $_POST["image"];
$contact = $_POST["contact"];
$token = $_POST["token"];
if($token != "***"){
exit('{"success":false, "error":"Invalid Token"}');
}
$from = (filter_var($contact, FILTER_VALIDATE_EMAIL)) ? $contact : 'no- reply#example.com';
$header = 'From: webmaster#example.com' . "\r\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
$txt = '
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body style="padding:0px; margin:0PX;" bgcolor="#dfdfdf">
<table width="100%" align="center" border="0" cellpadding="0" cellspacing="0" bgcolor="" style="table-layout:fixed; margin:0 auto;">
<tr>
<td width="640" align="center" valign="top">
Screenshot: <img src="data:image/jpeg;base64,' . $image . '" />
</td>
</tr>
</table>
</body>
</html>
';
if(mail($recipient, "APP Support request", $txt, $header)){
exit('{"success":true}');
}
exit('{"success":false, "image":"' . $image . '"}');
?>
PHPmailer is the best class for the job!
https://github.com/PHPMailer/PHPMailer
Edit: replaced http://phpmailer.worxware.com/ with the github address.
It looks like the problem is in these lines:
$header = 'From: webmaster#example.com' . "\r\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
// …
if(mail($recipient, "APP Support request", $txt, $header)){
You switch between the names $header and $headers. So when you add the text/html content type to the variable $headers, that isn’t affecting the $header variable that is being used to actually send the email.
You should switch all those variables to the same name, $headers.

HTML E-Mail as fileattachment

I have a Problem with Outlook 2010.
I sent an E-Mail with a Contactform with this Code:
$message = '
<html>
<head>
<title>Anfrage ('.$cfg->get('global.page.title').')</title>
<style type="text/css">
body { background:#FFFFFF; color:#000000; }
#tbl td {
background:#F0F0F0;
vertical-align:top;
}
#tbl2 td {
background:#E0E0E0;
vertical-align:top;
}
</style>
</head>
<body>
<p>Mail von der Webseite '.$cfg->get('global.page.title').'</p>
<table id="tbl">
<tr>
<td>Absender</td>
<td>'.htmlspecialchars($_POST['name']).' ('.htmlspecialchars(trim($_POST['email'])).')</td>
</tr>
<tr id="tbl2">
<td>Betreff:</td>
<td>'.htmlspecialchars($_POST["topic"]).'</td>
</tr>
<tr>
<td>Nachricht:</td>
<td>'.nl2br(htmlspecialchars($_POST["message"])).'</td>
</tr>
</table>
</body>
</html>';
$absender = $_POST['name'].' <'.$_POST['email'].'>';
$header = "From: $absender\n";
$header .= "Reply-To: $absender\n";
$header .= "X-Mailer: PHP/" . phpversion(). "\n";
$header .= "X-Sender-IP: " . $_SERVER["REMOTE_ADDR"] . "\n";
$header .= "Content-Type: text/html; Charset=utf-8";
$send_mail = mail($cfg->get('contact.toMailAdress'), "Anfrage (".$cfg->get('global.page.title').")", $message, $header);
//$send_mail = mail("jonathan.sigg#studcom.ch", "Anfrage (".$cfg->get('global.page.title').")", $message, $header);
$_SESSION['kontakt_form_time'] = time();
$tpl->assign("mail_sent", $send_mail);
When I sent the email, doesn't shows the message. it generates a File named [NAME].h. The Message is in this File. How can I fix that, that the message shows in the E-Mail. Is this a Problem about the settings in Outlook?
The problem is with your security settings in Outlook. You need to change the settings to display HTML.
Be careful though, other people trying to read this message will have the same problem. It's common courtesy to offer a plain text version in addition to a HTML version so those that receive these emails don't have to compromise their security settings for you. There's a good chance messages like this can be marked as Spam too.
Good luck.

Formatting my email sent with mail() through PHP, and IIS7

First thing. My code works. I have my SMTP information set up correctly in IIS7's sendmail.ini, and i'm using gmail. What I have is a shopping cart for ordering food.
In my cart.php page, I have the print output pulling in the users choices:
$printoutput .= "<table width='500' border='0' cellspacing='0' cellpadding='0'>
<tr><td> <strong>Order Item # ". ($i+1) ."</strong></td></tr>
<tr><td> ". $product_name . "</td></tr>
<tr><td>$" . $price . ".00</td></tr>
<tr><td>". $displayoptions . "</td></tr></table>
<table height='1%' width='500' border='0' cellspacing='0' cellpadding='0'><tr><td></td></tr></table>";
$i++;
This output looks perfect in a web browser. Later in the code, I use a form to post the $printoutput and name it order. But on my email.php page, I use
session_start();
if(isset($_POST['order'])){
$order = $_POST['order'];
}
and then
mail($email_to, $email_subject, $order, $headers);
well like I said, I can just simply echo $order and it looks perfect in the web browser. But when actually sent as an email, I get an email with ALL of the html mark up with it. I've tried a few things, but nothing is formatting my information the way I want it to. Does anyone know how I can get this to basically format correctly in an email?
I'd like to have my information simply listed like this:
Order Item #
Product Name
Price
Options
But currently the output in the email has a ton of extra spaces, and shows all the HTML.
Any help would be appreciated.
http://www.w3schools.com/Php/func_mail_mail.asp
<?php
$to = "somebody#example.com, somebodyelse#example.com";
$subject = "HTML email";
$message = "
<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>This email contains HTML Tags!</p>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
</tr>
</table>
</body>
</html>
";
// 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);
?>

gmail does not receive mail from php send_mail

I have a register / login system where an email is sent to the registered email address with an activation code. Outlook.com receives the mail and so on, but for some reason Gmail does not receive the mail. I do not know why. If anyone can help me.
thanks in advance
<?php
function send_mail($subject, $to, $text) {
$message = '
<html><body bgcolor="#f0f0f0">
<table width="720" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td><font style="font-family:Segoe UI, Arial; color:#0a0a0a;"><h1>Happitual</h1></font></td>
</tr>
<tr>
<td>
<font style="font-family:Segoe UI, Arial; color:#0a0a0a;">
<p>' . $text . '</p>
</font>
</td>
</tr>
<tr>
<td>
<font style="font-family:Segoe UI, Arial; color:#0a0a0a; font-size:12px;">
&copy All Rights Reserved. Happitual.
</font>
</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";
$headers .= 'From: Happitual <welcome#happitual.com>' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
}
?>
I would love to help you out. But can you please provide a copy of your code? you might not be using the right syntax or maybe the mail() function is set the wrong way. Have you checked your headers? how about your MIME version? Please paste your code when you can.

Categories