This question already has answers here:
php send e-mail with PDF attachment
(4 answers)
Closed 7 years ago.
Good day! My code is working great if the format is in msword but when i changed it to PDF it becomes corrupted what should i do? Please help me.
$headers = "From:<noreply#example.com.ph>";
$to = 'example#example.com';
$subject = 'Purchase Order';
$message .= 'Please see attached file';
$txt .=" <html> <body>
<p><b> PO Number:</b>
$purchasenumber</p>
<p><b> Style Code:</b> $styleCode</p>
<p><b> Generic Number:</b> $gennum</p>
<p><b> Vendor Name:</b> $vendname</p>
<p><b> Planned Delivery Date:</b>
$pdelivdate</p> <br/> <br/>
<table border=1 style='width:100%' cellpadding='0'>
<thead>
<tr>
<th width='16.7%'>Material Number</th>
<th width='16.7%'>Color</th>
<th width='16.7%'>Size</th>
<th width='16.7%'>Ordered QTY</th>
<th width='16.7%'>Total Cost</th>
<th width='16.7%'>Total SRP</th>
</tr>
</thead>
<tbody>
";
$statement = $db->prepare("SELECT * FROM purchaseorderproductitem where purchaseorderID = :pid");
$statement->execute(array(':pid' => $purchasenumber));
foreach ($statement->fetchAll() as $row)
{ $matnum = $row['materialnumber']; $color = $row['color']; $size = $row['size']; $qty = $row['quantity']; $units = $row['units']; $curcost = $qty * $cost; $cursrp = $qty * $srp; $curcost = number_format($curcost, 2, '.', ''); $cursrp = number_format($cursrp, 2, '.', '');
$txt .="
<tr> <td width='16.7%'>$matnum</td> <td width='16.7%'>$color</td> <td width='16.7%'>$size</td> <td width='16.7%'>$qty $units</td> <td width='16.7%'>$curcost</td> <td width='16.7%'>$cursrp</td> </tr>
";
}
$txt .="
<tr> <td width='16.7%' text-align:'center'>Total</td> <td width='16.7%'> </td> <td width='16.7%'> </td> <td width='16.7%'>$totalqty pcs</td> <td width='16.7%'>$totalcost</td> <td width='16.7%'>$totalsrp </td> </tr>
</body> </table> </html>
";
// Always set content-type when sending HTML email $message = "MIME-Version: 1.0" . "\r\n"; // $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; $message .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$fileatt_name2 = "PurchaseOrder.pdf";
$semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// Add the headers for a file attachment $headers .= "\nMIME-Version:
1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; $data2 = chunk_split(base64_encode($txt));
$message = "{$mime_boundary}\n" . "Content-Type: text/plain; charset=iso-8859-1; format=flowed\n" . "Content-Transfer-Encoding: 7bit\n\n" .
$message .= "{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" .
// Add file attachment to the message $message .= "--{$mime_boundary}\n" . "Content-Type: application/octet-stream;\n" . // {$fileatt_type} " name=\"{$fileatt_name2}\"\n" . "Content-Disposition: attachment;\n" . " filename=\"{$fileatt_name2}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data2 . "\n\n" . "--{$mime_boundary}--\n";
// Send the message $send = mail($to, $subject, $message, $headers);
Can you please help me to solve this issue? Thanks in advance!
You can use a combination of PHPMailer:
http://phpmailer.worxware.com/
And TCPDF:
http://www.tcpdf.org/
To accomplish this task. I will not cover the processes in detail as code examples would be quite tedious to create however both pieces of software have detailed documentation and examples found here:
https://github.com/Synchro/PHPMailer
And here:
http://www.tcpdf.org/docs.php
Edit:
If you do not want to to use something that just works like PHPMailer then I would ensure that the correct headers are being sent.
One useful trick i have found here too is that if you open said corrupted file in a text editor, you most usually find useful information at the very beginning relating to any errors that may have occurred while processing the output.
Edit:
Just guessing here but your last few lines of code I believe should read as follows:
// Add the headers for a file attachment
$headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . "boundary=\"{$mime_boundary}\""; $data2 = chunk_split(base64_encode($txt));
$headers .= "{$mime_boundary}\n"."Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n";
// Add file attachment to the message
$headers .= "--{$mime_boundary}\n" . "Content-Type: application/octet-stream;\n" . {$fileatt_type} " name=\"{$fileatt_name2}\"\n" . "Content-Disposition: attachment;\n" . " filename=\"{$fileatt_name2}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data2 . "\n\n" . "--{$mime_boundary}--\n";
// Send the message
$send = mail($to, $subject, $message, $headers);
You had concatenated the end of one of the statements instead of ending it with a semicolon ;
You were adding the headers to the $message variable, they should rather be in the $headers variable correct?
You had added one of the headers twice.
Related
I tinkered with an existing php email file to add the confirmation email section to get a HTML email for confirmation, the email works but it doesn't display html, it displays the code. Someone please let me know what I need to fix here?
I suspect its something to do with the headers.
I haven't done much PHP in a while.
<?php
$toEmail = "my#gmail.com";
if(isset($_POST['txtfirstname']))
{
$txtfirstname=$_POST['txtfirstname'];
$txtlastname=$_POST['txtlastname'];
$txtcompanyname=$_POST['txtcompanyname'];
$txttitle=$_POST['txttitle'];
$txtemail=$_POST['txtemail'];
$txtphone=$_POST['txtphone'];
$txtaddress=$_POST['txtaddress'];
$txtcity=$_POST['txtcity'];
$txtstate=$_POST['txtstate'];
$txtzipcode=$_POST['txtzipcode'];
$txtcountry=$_POST['txtcountry'];
$txtshirtsize=$_POST['txtshirtsize'];
$mimeHeaders .= "MIME-Version: 1.0\r\n";
$mailHeaders .= "X-Priority: 3\r\n";
$mailHeaders .= "X-Mailer: PHP". phpversion() ."\r\n";
//$mailHeaders .= "Content-Type: text/html; charset=iso-8859-1\n";
//headers
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers = "From: " . $txtfirstname." ".$txtlastname . "<". $txtemail .">\r\n";
$headers .= "Reply-To: ". $txtfirstname." ".$txtlastname . "<". $txtemail .">\r\n";
$headers .= "Return-Path: ". $txtfirstname." ".$txtlastname . "<". $txtemail .">\r\n";
$subject = "New Registration";
$content = "New Registration \r\n";
$content = $content. "First Name : ".$txtfirstname. "\r\n";
$content = $content. "Last Name : ".$txtlastname . "\r\n";
$content = $content. "Company : ".$txtcompanyname . "\r\n";
$content = $content. "Title : ".$txttitle . "\r\n";
$content = $content. "Email : ".$txtemail . "\r\n";
$content = $content. "Phone : ".$txtphone ."\r\n";
$content = $content. "City : ".$txtcity . "\r\n";
$content = $content. "State : ".$txtstate . "\r\n";
$content = $content. "Zip Code : ".$txtzipcode . "\r\n";
$content = $content. "Country : ".$txtcountry . "\r\n";
// Subject of confirmation email.
$conf_subject = 'Confirmation Emailer';
// Who should the confirmation email be from?
$conf_sender = 'Me <mygmail.com>';
// HTML email message
$conf_message = '
<html>
<head>
<title>HTML email</title>
</head>
<body>
<table border="0" style="width: 500px; border-collapse: collapse; margin-left: auto; margin-right: auto;" cellpadding="0" cellspacing="0"> <tbody> <tr> <td style="width: 100%;"><img src="/banner.jpg" alt="Title" /></td> </tr> <tr> <td style="width: 100%;"><p><span><strong>Congratulations!</strong></span></p>
<p> </p>
<p>You have successfully registered ’</p> <p> </p> <p>Click below to add this event to your calendar-</p>
<p><br /><u><strong>Add to your calendar</strong></u></p>
<p><br />If you require any further assistance or have any queries, please reach out to us at <b>me#<wbr />gmail.com</b></p>
<p><br />We’re looking forward to your presence at the event.</p>
<p><br />23 th December 2020 | 8:45 AM .</p>
</td> </tr>
</tbody> </table>
</body>
</html>
';
mail( $_POST['txtemail'], $conf_subject, $conf_message,'From: ' . $conf_sender );
if(isset($_POST['chkgiveaway']) && $_POST['chkgiveaway']=="Yes")
{
$content = $content. "Want to receive Give aways: ".$_POST['chkgiveaway']. "\r\n";
$content = $content. "Shirt Size: ".$_POST['txtshirtsize']. "\r\n";
$content = $content. "Mailing Address : " . "\r\n";
$content = $content. "Address : ".$_POST['txtaddressgiveaway'] . "\r\n";
$content = $content. "City : ".$_POST['txtcitygiveaway'] . "\r\n";
$content = $content. "State : ".$_POST['txtstategiveaway'] . "\r\n";
$content = $content. "Zip Code : ".$_POST['txtzipcodegiveaway'] . "\r\n";
$content = $content. "Country : ".$_POST['txtcountrygiveaway'] . "\r\n";
}
if(mail($toEmail, $subject, $content, $mailHeaders)) {
$message = "<h4>Thank you, your details have been successfully submitted.</h4>";
echo $message;
}
} else {
echo "Invalid submission";
}
?>
You didn't add the headers
mail( $_POST['txtemail'], $conf_subject, $conf_message, $headers);
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 7 years ago.
How to send mail using php by insert html into mail content ?
I tried to insert html code inner $message, When i test it's show error
like this Parse error: syntax error, unexpected 'margin' (T_STRING)
How can i do ?
<?PHP
include("connect.php");
$email = "test_mail#hotmail.com";
$to = $email;
$subject = "test subject";
$message = "
<body style="margin: 0; padding: 0;">
<table border="1" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td>
<img src="http://i.stack.imgur.com/Jy9QUm.jpg"/>
</td>
</tr>
<tr>
<td>
test text
</td>
</tr>
</table>
</body>
";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: EXAMPLE <noreply#example.com>' . "\r\n";
$headers .= 'Return-Path: return#example.com' . "\r\n";
mail($to, $subject, $message, $headers, '-freturn#example.com');
?>
You have an issue with wrapping your $body string try this
<?PHP
include("connect.php");
$email = "test_mail#hotmail.com";
$to = $email;
$subject = "test subject";
$message = "
<body style='margin: 0; padding: 0;'>
<table border='1' cellpadding='0' cellspacing='0' width='100%'>
<tr>
<td>
<img src='http://i.stack.imgur.com/Jy9QUm.jpg'/>
</td>
</tr>
<tr>
<td>
test text
</td>
</tr>
</table>
</body>
";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: EXAMPLE <noreply#example.com>' . "\r\n";
$headers .= 'Return-Path: return#example.com' . "\r\n";
mail($to, $subject, $message, $headers, '-freturn#example.com');
?>
i am trying to figure out writing html in php file. it seems that php does not recognise all the html tag like font, img. it gave an error. I tried echo 'html stuff'; but it dont seem to work as well.
I have left out the other $var declaration in the code below. the script is working except when i tried to add font size or img tags.
<?php
header("Content-type: html");
$message = "
<!DOCTYPE html>
<html>
<head>
<title>New Loan Enquiry</title>
</head>
<body>
<h2><strong>Time of Enquiry: $today</strong></h2>
Name: $name<br>
Email: $email<br>
Contact: $contact<br>
Buy_Stage: $buystage<br>
Property Type: $pty_type<br>
Property Stage: $pty_stage<br>
Purchase Price: $purchaseprice<br>
Loan Amount: $loanamt<br>
Rate Type: $rate_type<br>
Comments: $comments<br><br>
</body>
</html>
";
mail($to,$subject,$message,$headers);
?>
where did i go wrong? It recognize h2 but not h1 or h3.
do i have to do like
echo ' html';
for each html code line?
Please check mail() in documentation.
To send email with html content you need to do this way:
<?php
$to = 'aidan#example.com';
// subject
$subject = 'subject of email';
// message
$message = 'some html content...';
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
?>
and you don't need to use:
header("Content-type: html");
you need to add
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: <from#example.com>' . "\r\n";
$headers .= 'Cc: cc#example.com' . "\r\n";
and remove
header("Content-type: html");
I find it best to style Html email in php by using tables and inline styles like below. here is a link to reference. Link, Sadly internal and external style sheets don't always work across different email clients.
<?php
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
$message = '<html>';
$message .= '<head>';
$message .= '<title>New Loan Enquiry</title>';
$message .= '</head>';
$message .= '<body>';
$message .= '<h2><strong>Time of Enquiry: $today</strong></h2>';
$message .= '<img src="http://YOUR_IMAGE_URL"/>;
$message .= '<table width="auto" border="0" cellspacing="3px" cellpadding="0">';
$message .= '<tr><td><strong>Name:</strong></td>';
$message .= '<td style=" font-weight:300 color:#CC0000">\$name</td></tr>';
$message .= '<tr><td><strong>Email:</strong></td>';
$message .= '<td style=" font-weight:300 color:#CC0000">\$email</td></tr>';
$message .= '<tr><td><strong>Contact:</strong></td>';
$message .= '<td style=" font-weight:300 color:#CC0000">\$contact</td></tr>';
$message .= '<tr><td><strong>Buy_Stage:</strong></td>';
$message .= '<td style=" font-weight:300 color:#CC0000">\$buystage</td></tr>';
$message .= '<tr><td><strong>Property Type:</strong></td>';
$message .= '<td style=" font-weight:300 color:#CC0000">\$pty_type</td></tr>';
$message .= '<tr><td><strong>Property Stage:</strong></td>';
$message .= '<td style=" font-weight:300 color:#CC0000">\$pty_stage</td></tr>';
$message .= '<tr><td><strong>Purchase Price:</strong></td>';
$message .= '<td style=" font-weight:300 color:#CC0000">\$purchaseprice</td></tr>';
$message .= '<tr><td><strong>Loan Amount:</strong></td>';
$message .= '<td style=" font-weight:300 color:#CC0000">\$loanamt</td></tr>';
$message .= '<tr><td><strong>Rate Type:</strong></td>';
$message .= '<td>\$rate_type</td></tr>';
$message .= '<tr><td><strong>Comments:</strong></td>';
$message .= '<td style=" font-weight:300 color:#CC0000">\$comments</td></tr>';
$message .= '</table>';
$message .= '</body></html>';
mail($to,$subject,$message,$headers);
?>
RESOLVED: The issue was a missing "\r\n" at the tail end of the line reading:
. "Contact " . $from . " for tech support."
Thank you everyone for your help and suggestions!
I'm trying to make a PHP function that will send an email with some HTML body and an attached image. I've perused several of the answers on this site and online tutorials and I'm unable to see where I'm going wrong. My current code attaches an image and sends the email successfully but the HTML body is missing and I receive an empty email with my attached image.
The raw source of the email I receive appears to have my HTML in it however none of my email clients render this HTML. See the source below:
Return-path: <sidesul6#slan-550-84.anhosting.com>
Envelope-to: admin#sideapps.com
Delivery-date: Thu, 05 Jun 2014 18:20:36 -0600
Received: from sidesul6 by slan-550-84.anhosting.com with local (Exim 4.82)
(envelope-from <sidesul6#slan-550-84.anhosting.com>)
id 1Wshtc-003XAD-04
for admin#sideapps.com; Thu, 05 Jun 2014 18:20:36 -0600
To: admin#sideapps.com
Subject: attachmentTest
X-PHP-Script: sideapps.com/phpMail/mailFunc.php for 74.70.70.214
From:noreply#sideapps.com
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="12cbb4220ad618027879b43ba5293d9d"
Message-Id: <E1Wshtc-003XAD-04#slan-550-84.anhosting.com>
Date: Thu, 05 Jun 2014 18:20:36 -0600
Sorry, your client doesn't support MIME types.
Contact noreply#sideapps.com for tech support.--12cbb4220ad618027879b43ba5293d9d
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
<html>
<body>
<p>Testing <i><b>HTML</b></i> right now.</p>
</body>
</html>
--12cbb4220ad618027879b43ba5293d9d
Content-Type: image/png; name="test.png"
Content-Transfer-Encoding: base64
Content-disposition: attachment; file="test.png"
<base64 image encoding>
See my function below:
function GetHTML()
{
return <<<HTML
<html>
<body>
<p>Testing <i><b>HTML</b></i> right now.</p>
</body>
</html>
HTML;
}
function mailAttachment($to, $subject, $body, $from, $photoPath, $photoName, $filetype)
{
$bound_text = md5(uniqid(rand(), true));;
$bound = "--" . $bound_text . "\r\n";
$bound_last = "--" . $bound_text . "--\r\n";
$headers = "From: " . $from . "\r\n"
. "Reply-To: " . $from . "\r\n"
. "Return-Path: " . $from . "\r\n"
. "MIME-Version: 1.0\r\n"
. "Content-Type: multipart/mixed; boundary=\"$bound_text\"";
$message = "Sorry, your client doesn't support MIME types.\r\n"
. "Contact " . $from . " for tech support."
. $bound;
$message .= "Content-Type: text/html; charset=\"iso-8859-1\"\r\n"
. "Content-Transfer-Encoding: 7bit\r\n\r\n"
. $body . "\r\n"
. $bound;
$file = file_get_contents($photoPath);
$message .= "Content-Type: $filetype; name=\"$photoName\"\r\n"
. "Content-Transfer-Encoding: base64\r\n"
. "Content-disposition: attachment; file=\"$photoName\"\r\n"
. "\r\n"
. chunk_split(base64_encode($file))
. $bound_last;
if(mail($to, $subject, $message, $headers))
{
echo 'MAIL SENT!' . '<br>';
echo 'to: ' . $to . '<br>';
echo 'from: ' . $from . '<br>';
echo 'bodyText: ' . $body . '<br>';
echo 'photoPath: ' . $photoPath . '<br>';
echo 'photoName: ' . $photoName . '<br>';
echo 'filetype: ' . $filetype . '<br>';
}
else
{
echo 'MAIL FAILED';
}
}
mailAttachment('admin#sideapps.com', 'attachmentTest', GetHTML(),
'noreply#sideapps.com', 'testImage.png', 'uploaded.png', 'image/png');
There is a missing "\r\n" at the tail end of the line reading:
. "Contact " . $from . " for tech support."
Below is the ammended function:
function GetHTML()
{
return <<<HTML
<html>
<body>
<p>Testing <i><b>HTML</b></i> right now.</p>
</body>
</html>
HTML;
}
function mailAttachment($to, $subject, $body, $from, $photoPath, $photoName, $filetype)
{
$bound_text = md5(uniqid(rand(), true));;
$bound = "--" . $bound_text . "\r\n";
$bound_last = "--" . $bound_text . "--\r\n";
$headers = "From: " . $from . "\r\n"
. "Reply-To: " . $from . "\r\n"
. "Return-Path: " . $from . "\r\n"
. "MIME-Version: 1.0\r\n"
. "Content-Type: multipart/mixed; boundary=\"$bound_text\"";
$message = "Sorry, your client doesn't support MIME types.\r\n"
. "Contact " . $from . " for tech support.\r\n"
. $bound;
$message .= "Content-Type: text/html; charset=\"iso-8859-1\"\r\n"
. "Content-Transfer-Encoding: 7bit\r\n\r\n"
. $body . "\r\n"
. $bound;
$file = file_get_contents($photoPath);
$message .= "Content-Type: $filetype; name=\"$photoName\"\r\n"
. "Content-Transfer-Encoding: base64\r\n"
. "Content-disposition: attachment; file=\"$photoName\"\r\n"
. "\r\n"
. chunk_split(base64_encode($file))
. $bound_last;
if(mail($to, $subject, $message, $headers))
{
echo 'MAIL SENT!' . '<br>';
echo 'to: ' . $to . '<br>';
echo 'from: ' . $from . '<br>';
echo 'bodyText: ' . $body . '<br>';
echo 'photoPath: ' . $photoPath . '<br>';
echo 'photoName: ' . $photoName . '<br>';
echo 'filetype: ' . $filetype . '<br>';
}
else
{
echo 'MAIL FAILED';
}
}
mailAttachment('admin#sideapps.com', 'attachmentTest', GetHTML(),
'noreply#sideapps.com', 'testImage.png', 'uploaded.png', 'image/png');
This doesn't attach a file, but you can embed an image within the HTML. Looks like you have the attachment part sorted though. Perhaps this will help with the html content.
This code works in a work environment stuck in 2007, haven't fully tested it with modern browsers, versions of Outlook past 2007, etc.
IIRC, the trick was embedding the full html into the email body and working with tables.
HTML :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
<title>Order</title>
</head>
<body>
<style type="text/css">
table#bodyTable {}
table#emailContainer {}
</style>
<table width="100%" height="100%" cellpadding="0" cellspacing="0" border="0" id="bodyTable">
<tr><td align="center" valign="top">
<div style="overflow: hidden;">
<table border="0" cellpadding="0" cellspacing="0" width="800" id="emailContainer">
<tr><td align="center" valign="top">
<table style="font-family:Tahoma;font-size:13px" width="500" align="center">
<tr bgcolor="#ffffff"><td style="padding:10px;color:#000000;" align="left" bgcolor="#ffffff">
<div style="margin: 15px;float:left;">
<img alt="YourImageAltText" border="0" src="http://your.domain/img/yourImage.jpg" height="48" width="230" />
</div>
</td></tr>
<tr><td style="padding:18px 30px 10px;font-size:11px" align="left">
<div style="font-size:12px">
This email is to confirm your recent job submission
</div>
</tr></td>
<tr bgcolor="#ffffff"><td style="padding:10px;color:#000000" align="center"></td></tr>
</table>
</td></tr>
</table><!-- End central content table, fixed width, aligned to center based upon master table -->
</div>
</td></tr>
</table><!-- end master containing table -->
</body>
</html>
PHP:
I build the $msg string with dynamic content and an external template, using
include('./templates/teamNotificationEmailBody.php');
function orderMail($sendTo, $subject, $msg, $errorRedirect, $successRedirect) {
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: DoNotReply#Wherever.com';
if (isset($sendTo))
{
$email = filter_var($sendTo, FILTER_SANITIZE_EMAIL);
if (!filter_var($email, FILTER_VALIDATE_EMAIL))
{
echo "<hr/>$email is <strong>NOT</strong> a valid email address.<br/><br/>Please return to the reservation form and enter a valid email address.<hr/><br/>Return $errorRedirect<br/>";
exit();
}
}
if (mail($sendTo, $subject, $msg, $headers))
{
if (isset($successRedirect))
{
echo "$successRedirect";
header("location: $successRedirect");
exit();
}
}
else
{
echo "<hr/>An error occured with the email notification system. <br/><br/><hr/><br/>Click here to return<br/>";
exit();
}
This what I have I tried to put it in a table just like:
<table>
<tr><td>$_POST['onderwerp']</td></tr>
</table>
This is what I have it sends the mail but it's to messy:
<?php
$to = 'example#gmail.com';
$subject = 'Vraag via de website';
$message = 'Onderwerp:'. $_POST['onderwerp'].'<br /><br />'.$_POST['vraag'].'<br /><br />'.'Telefoonummer:'. $_POST['tel'].'<br /><br />'.'Email:'. $_POST['email'] ;
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To:<eexample#gmail.com>' . "\r\n";
$headers .= 'The shop<example#gmail.com>' . "\r\n";
mail($to, $subject, $message, $headers);
header('Location: contact.html');
?>
I just want to send the variables in a table so that I don't have to search through all the text.
<?php
$to = 'user#example.com';
$subject = 'Vraag via de website';
$msg = "<html>
<head>
<title>Title of email</title>
</head>
<body>
<table cellspacing=\"4\" cellpadding=\"4\" border=\"1\" align=\"center\">
<tr>
<td align=\"center\">Onderwerp</td>
<td align=\"center\"> vraag</td>
<td align=\"center\">Telefoonummer</td>
<td align=\"center\">Email</td>
</tr>
<tr>
<td align=\"center\">".$_POST['onderwerp']."</td>
<td align=\"center\">".$_POST['vraag']."</td>
<td align=\"center\">".$_POST['tel']."</td>
<td align=\"center\">".$_POST['email']."</td>
</tr>
</table>
</body>
</html>";
// Make sure to escape quotes
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: My Site Name <me#mysite.com>' . "\r\n";
mail($to, $subject, $msg, $headers);
?>
you could try this using your variables.
$var = 'test';
$var2 = 'test2';
echo '<table border="1">';
echo '<tr><td>' . $var . '</td></tr>';
echo '<tr><td>' . $var . '</td></tr>';
echo '</table>';
this will show the variables in a table, then you can edit the table using css how you want. :)
I suggest that you include swiftmailer.
Swiftmailer makes sure emails get delivered in the Inbox and you can easily include HTML markup in your emails:
Swiftmailer HTML in email
Just download the Swiftmailer Library, include and configure it like this example:
Sending an email in swiftmailer
Let me know if this helps you out!