Mail message and attachment in php - php

Im trying to send a mail attachment in php.
Here is the code which im trying but dont know whats wrong in this:
please can anyone suggest any modification for the following code
<?php
$path = "files/";
$files = "myfile.csv";
$par_mailto = "RECEIVER MAIL ID";
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// headers for attachment
$headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";
// multipart boundary
$message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/html; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n";
$message .= "--{$mime_boundary}\n";
// preparing attachments
$file = fopen($path.$files,"rb");
$data = fread($file,filesize($path.$files));
fclose($file);
$data = chunk_split(base64_encode($data));
$message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$files\"\n" .
"Content-Disposition: attachment;\n" . " filename=\"$files\"\n" .
"Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
$message .= "--{$mime_boundary}\n";
//mail attachment ends
$date = date_default_timezone_set('Asia/Kolkata');
$today = date("F j, Y, g:i a T");
$subject = "Test mail on ".$today ;
$header .= 'MIME-Version: 1.0' . "\r\n". 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers = $header."From: info#ziddu.com ". "\r\n"
. "Cc: $par_mailcc" . "\r\n";
//!!!All the emails are coming with comma as separator .... "\r\n\" is important to separate FROM Cc BCc.
$message .= "<html><body>";
//
$message .= "<table width='800' cellspacing='5' cellpadding='5' border='0' align='center' style='border:1px solid #e6e6e6'>
<tbody><tr>
<td height='80' bgcolor='#F3F3F3' style='padding-left:15px'><table width='100%' cellspacing='0' cellpadding='0' border='0'>
<tbody><tr>
<td width='50%' align='center'></td>
</tr>
</tbody></table></td>
</tr>
<tr>
<td valign='top' height='150'>
<p style='font:normal 15px Arial,Helvetica,sans-serif;color:#666666;'>Dear Mr. ".$_SESSION['name'].",</p>
<p style='font:normal 15px Arial,Helvetica,sans-serif;color:#666666;'>This is the test mail with an attachment</b></p>
";
$message .= "
<div style='width:584px;background-color:#ffffff;border:#e8e7e7 solid 1px;padding:27px 0;margin:0 auto;border-bottom:0'>
<div style='border-bottom:#717171 dotted 1px;font:normal 14px Arial,Helvetica,sans-serif;color:#666666;padding:0px 33px 10px'>
<table cellspacing='0' cellpadding='2' border='0' style='width:100%'>
<tbody>
<tr>
<td width='400px'> <span style='color:#333333;font-weight:600'>Transaction Details: </span></td>
</tr>
</tbody>
</table>
</div>
<div style='border-bottom:#717171 dotted 1px;font:normal 14px Arial,Helvetica,sans-serif;color:#666666;padding:10px 33px 10px'>
<table cellspacing='0' cellpadding='2' border='0' style='width:100%'>
<tbody>
<tr>
<td width='350px'>Transfered </td>
<td>USD 10000</td>
</tr>
</tbody>
</table>
</div>
<div style='border-bottom:#717171 dotted 1px;font:normal 14px Arial,Helvetica,sans-serif;color:#666666;padding:10px 33px 10px'>
<table cellspacing='0' cellpadding='2' border='0' style='width:100%'>
<tbody>
<tr>
<td width='350px'>Fee</td>
<td>USD 200</td>
</tr>
</tbody>
</table>
</div>
<div style='border-bottom:#717171 dotted 1px;font:normal 14px Arial,Helvetica,sans-serif;color:#666666;padding:10px 33px 10px'>
<table cellspacing='0' cellpadding='2' border='0' style='width:100%'>
<tbody>
<tr>
<td width='350px'>Total</td>
<td>USD 4000</td>
</tr>
</tbody>
</table>
</div>
<div style='font:normal 12px Arial,Helvetica,sans-serif;color:#666666;padding:10px 33px 0px'>
<table cellspacing='0' cellpadding='2' border='0' style='width:100%'>
<tbody>
</tbody>
</table>
</div>
</div>
<div style='margin:0 auto;width:594px'><img alt='' src='https://ci4.googleusercontent.com/proxy/Rku_qr-ooNg8yw1tsELcIxO6HBPXzNZtY_bfb9r8yySSxzteTaIxDoJ83pE5XmtwvZO7O5UC4wM31f_rVlP6HyR9VK2OrStgu8llNx45_L81Jv7YD6P1=s0-d-e1-ft#https://dx87hk8eoofvk.cloudfront.net/images/email/receiptedge.png' title=''></div>";
$message .="<p style='font-family:verdana'><br><b>IMPORTANT:</b>"
. " Please do not reply to this message or mail address. For any queries,please mail to info#ziddu.com \n\n</p>";
$message .="<p style='font-family:verdana'><b>DISCLAIMER:</b>"
. " This communication is confidential and privileged and is directed to and for the use of the addressee only. "
. "The recipient if not the addressee should not use this message if erroneously received, "
. "and access and use of this e-mail in any manner by anyone other than the addressee is unauthorized. "
. "The recipient acknowledges that Ziddu.com may be unable to exercise control or ensure or guarantee the "
. "integrity of the text of the email message and the text is not warranted as to completeness and accuracy. "
. "\n\n</p><br>";
$message .="<p style='font-family:verdana'>Regards,<br>Ziddu Team <br>www.ziddu.com \n\n</p>";
$message .="</td>
</tr>
<tr>
<td height='30' bgcolor='#E9E9E9' align='center'><strong>Upload.. Share.. Earn!</strong></td>
</tr>
</tbody></table>";
#mail($par_mailto, $subject, $message, $headers);
?>
As i need to add some more information with design and all also had an attachment that needs to be attached. Got confused where im gone wrong

Related

Send multiple rows to one email but send multiple email with row wise

I want to send email with multiple rows from database in php but when I send email that time send multiple email with single row data but I want single email with multiple rows.
I don't know where I am wrong. Below is my running code in php and mysql.
$fm_id = $_POST['fm_id'];
$issue = $_POST['issue'];
$resolution = $_POST['resolution'];
$fstatus = $_POST['fstatus'];
$date3= date("Y-m-d h:i:s");
$time2= date("h:i:s");
for ($i = 0; $i < count($fm_id); $i++)
{
$update=("UPDATE fm_status SET problem='$issue[$i]', solution='$resolution[$i]',status='$fstatus[$i]' WHERE fm_id='$fm_id[$i]'");
$res=mysql_query($update);
$update1=("UPDATE fm_status SET date2='$date3', time2='$time2' WHERE fm_id='$fm_id[$i]'");
$res1=mysql_query($update1);
$to ='abc#gmail.com'. ', ';
$to .='abc#abc.com';
$subject="Ticket Details from ";
$header="Solution ";
$header = 'MIME-Version: 1.0' . "\r\n";
$header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$header .= 'From: FM Engineer<solution#abc.com>' . "\r\n" ;
$message = '<html><body>';
$message .= '<head>';
$message .= '</head>';
$message .= " <align=center> <div id='apDiv2'>
<table id='table1' border='1' cellpadding='5' cellspacing='5' class='tinytable cf'>
<thead>
<tr>
<th><h3> Raised By </h3></th>
<th><h3> Issue </h3></th>
<th><h3> Resolution </h3></th>
<th><h3> Status </h3></th>
</tr> </thead>
<tbody>
<td> ".$issue[$i]."</td>
<td> ".$issue[$i]."</td>
<td> ".$resolution[$i]."</td>
<td> ".$issue[$i]."</td>
</tr><tbody></table>";
$message .= '<br>';
$message .= "</body></html>";
$sentmail = mail($to,$subject,$message,$header);
echo $sentmail;
}
I think this is more along the lines of what you are looking for (I am not going to reiterate the warnings regarding mysql_* functions). If you are trying to add rows to your table to send in one email, then just have the rows built by the for loop like so:
$fm_id = $_POST['fm_id'];
$issue = $_POST['issue'];
$resolution = $_POST['resolution'];
$fstatus = $_POST['fstatus'];
$date3= date("Y-m-d h:i:s");
$time2= date("h:i:s");
$to ='abc#gmail.com'. ', ';
$to .='abc#abc.com';
$subject="Ticket Details from ";
$header="Solution ";
$header = 'MIME-Version: 1.0' . "\r\n";
$header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$header .= 'From: FM Engineer<solution#abc.com>' . "\r\n" ;
$message = '<html>';
$message .= '<head>';
$message .= '</head><body>';
$message .= " <align=center> <div id='apDiv2'>
<table id='table1' border='1' cellpadding='5' cellspacing='5' class='tinytable cf'>
<thead>
<tr>
<th><h3> Raised By </h3></th>
<th><h3> Issue </h3></th>
<th><h3> Resolution </h3></th>
<th><h3> Status </h3></th>
</tr> </thead>
<tbody>";
for ($i = 0; $i < count($fm_id); $i++)
{
$update=("UPDATE fm_status SET problem='$issue[$i]', solution='$resolution[$i]',status='$fstatus[$i]' WHERE fm_id='$fm_id[$i]'");
$res=mysql_query($update);
$update1=("UPDATE fm_status SET date2='$date3', time2='$time2' WHERE fm_id='$fm_id[$i]'");
$res1=mysql_query($update1);
$message .= "<tr>
<td> ".$issue[$i]."</td>
<td> ".$issue[$i]."</td>
<td> ".$resolution[$i]."</td>
<td> ".$issue[$i]."</td>
</tr>";
}
$message .= '<tbody></table><br>';
$message .= "</body></html>";
$sentmail = mail($to,$subject,$message,$header);
echo $sentmail;

Send HTML links in php mail message

I am trying to send a html link in mail using php. But I am getting the full text of html in the mail. Below is the code what I have tried . But it is not working. Any help is appreciated.
$emailid = $_POST['email'];
$phoneno = $_POST['phoneno'];
$to = "demoemail#gmail.com"; // this is your Email address
$from = $emailid; // this is the sender's Email address
$subject = "Intrested in scheduling appointment.";
$message = "<a href='http://www.google.com'>Click Here</a>";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers = "From:" . $from;
$retval = mail($to,$subject,$message,$headers);
Below is what I am getting in mail with tag
http://www.google.com'> Click Here
I've checked with your code..
Seems like you are making a simple mistake..
You are not concatenating your code.. you are re assigning your header at line 3
Your Code
$emailid = $_POST['email'];
$phoneno = $_POST['phoneno'];
$to = "demoemail#gmail.com"; // this is your Email address
$from = $emailid; // this is the sender's Email address
$subject = "Intrested in scheduling appointment.";
$message = "<a href='http://www.google.com'>Click Here</a>";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers = "From:" . $from;
$retval = mail($to,$subject,$message,$headers);
Updated Code on headers:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From:" . $from;
Update your header and try again!
Thanks! Have a nice day!
Working code with template paste and run
<?
$to = $send_to;
$subject = $mail_subject;
$message .= '<div style="margin:0;font-weight:lighter;background:#f0f4f7;">
<table class="m_6501530908114331344layout" style="font-family:Helvetica,Arial,sans-serif;background:#f0f4f7;width:100%">
<tbody><tr>
<td>
<table cellspacing="0" class="m_6501530908114331344page-container" width="505" align="middle" style="font-family:Helvetica,Arial,sans-serif;border-spacing:0;background-color:#fff;max-width:505px!important;display:block!important;margin:25px auto!important;clear:both!important">
<tbody><tr class="m_6501530908114331344header" style="background-color:rgba(218, 23, 23, 0.03);">
<td class="m_6501530908114331344row" style="border-left:1px solid #e7e7e7;border-right:1px solid #e7e7e7;border:none;padding:20px 35px">
<img alt="lasaioffice" height="80" width="300" src="https://www.google.co.in/images/branding/googlelogo/2x/googlelogo_color_120x44dp.png" class="CToWUd">
</td>
</tr>
<tr class="m_6501530908114331344subject" style="background-color:#fff">
<td class="m_6501530908114331344primary-message" style="padding:20px 35px 0">
<p style="margin:20px 0;line-height:1.45">Hi google </p>
<h2 class="m_6501530908114331344centered" style="font-size:24px;font-weight:bold;margin:0;margin-bottom:30px;display:block;text-align:center;margin-bottom:0;color:#eb2028;">
Just one more click
</h2>
<table class="m_6501530908114331344email-btn" style="font-family:Helvetica,Arial,sans-serif;background:#eb2028;padding:10px">
<tbody><tr>
<td>
Activate Account
</td>
</tr>
</tbody>
</table>
<p style="margin:20px 0;line-height:1.45">
<strong style="font-weight:bold">
Kind Regards, <br>
The google Team
</strong>
</p>
</td>
</tr>
<tr class="m_6501530908114331344footer" style="color:#7f8da0">
<td class="m_6501530908114331344footer-tagline" style="padding:0 35px">
<hr class="m_6501530908114331344footer-line-break" style="margin-bottom:35px;border:0;border-bottom:1px solid #d3dbe3">
<p class="m_6501530908114331344small" style="font-size:12px">
<strong style="font-weight:bold">
<a style="color:#eb2028;" href="http://google.com">google</a> -
The leading marketplace selling google.
</strong>
</p>
<p class="m_6501530908114331344small" style="font-size:12px">
This account notification was sent to you because you are a google user.
Should you have any questions, you are welcome to email us.
</p>
</td>
</tr>
<tr class="m_6501530908114331344footer" style="color:#7f8da0">
<td class="m_6501530908114331344footer-links" style="padding:20px 35px 45px">
<p class="m_6501530908114331344small" style="font-size:12px">
Copyright © 2017 | google Pty Ltd. All rights reserved.
</p>
</td>
</tr>
</tbody></table>
</td>
</tr>
</tbody></table>
<img src="" alt="" width="1" height="1" border="0" style="height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important" class="CToWUd"><div class="yj6qo"></div><div class="adL">
</div></div>';
$header = "From:abc#gmail.com \r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-type: text/html\r\n";
$retval = mail ($to,$subject,$message,$header);
if( $retval == true ) {
echo "Message sent successfully...";
}else {
echo "Message could not be sent...";
}
?>

php email from name header based on user name input

What am I doing wrong here. When a user submits the form, it shows up in my inbox with their name as their email address and I would like it to be the name that they input in the form. here is my code.
<?php
//error_reporting(0);
//include("connection.php");
$n=$_POST['name'];
$e=$_POST['email'];
$p=$_POST['phone'];
$t1=$_POST['tot_eth'] ;
$t2=$_POST['tot_tax'];
$t3=$_POST['tot_acct'];
$t4=$_POST['tot_tot'];
$i=1;
while($i<13)
{
${'date' . $i} = $_POST["date$i"] ;
${'seminar'.$i}=$_POST["seminar$i"] ;
${'sponser'.$i}=$_POST["sponser$i"] ;
${'ethics'.$i}=$_POST["ethics$i"] ;
${'tax'.$i}=$_POST["tax$i"] ;
${'acct'.$i}=$_POST["acct$i"] ;
${'t'.$i}=$_POST["total$i"] ;
$i++;
}
//session_start();
$to = "mj#ntatax.com";
$from=$n $e;
$subject = "2015 CPE Verification Form";
// compose headers
$headers = 'From: '. $_POST['name'] . ' <' . $e . '>\r\n' .
'Reply-To:' .$from . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// compose message
$message ='<html>
<body>
<p>
From Name : '.$n.'<br>
From Email : '.$e.'<br>
Phone Number : '.$p.'<br><br>
</p>
<table cellpadding="5"> <tr>
<td>Date </td>
<td>Seminar Attended and Location </td>
<td>Sponsor </td>
<td>Ethics Hours </td>
<td>Tax Hours </td>
<td>Acct Hours</td>
<td>Total Hours</td>
</tr>
';
for ($i=1;$i<=13;$i++){
$message .='<tr>
<td>'.${'date' . $i}.'</td>
<td>'.${'seminar'.$i}.'</td>
<td>'.${'sponser'.$i}.'</td>
<td>'.${'ethics'.$i}.'</td>
<td>'.${'tax'.$i}.'</td>
<td>'.${'acct'.$i}.'</td>
<td>'.${'t'.$i}.'</td>
</tr>';
}
$message .=' <tr></tr>
<tr>
<td colspan=2>
<td><p style="text-align: right">Total</p></td>
<td>'.$_POST['tot_eth'].'</td>
<td>'.$_POST['tot_tax'].'</td>
<td >'.$_POST['tot_acct'].'</td>
<td >'.$_POST['tot_tot'].'</td> </td>
</tr> </table>
</body>
</html>';
$message = wordwrap($message, 270);
// send email
mail($to,$subject, $message, $headers,"'".'-f '.$from."'");
// mail($to,$subject, $message, $headers,"'".'-f '.$from."'");
session_start();
//$_SESSION['send1']="Thanks For Contacting Us,Your Query Will Be Replied At the Earliest.";
header("location:http://www.waainc.org");
?>

multiple file uploaded is not attaching to mail

my html form for file upload is
<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
<input type="file" id="file" name="files[]" multiple="multiple" />
<input type="submit" id="submit" name="submit" value="Submit"/>
</form>
And the php code for mail sending is:
$to = "my email id";
$subject ="Registration";
$message ="<div style='border: 5px solid #B8B8B8;'><table border='0'cellspacing='0' cellpadding='10' >
<tr><td colspan='4'>Hi ,</td></tr>
<tr><td colspan='4'>A new report</td></tr>
<tr><td colspan='4'>Details are:</td></tr>
<tr> <td><table width='100%'>
<tr><td><table border='1'cellspacing='0' cellpadding='0' width='98%'>
<tr><td colspan='3' style='padding-left:10px; font-family:Arial, Helvetica, sans-serif; font-size:14px;' height='20px;' >Name : ".$sname."</td><td colspan='3' style='padding-left:10px; font-family:Arial, Helvetica, sans-serif; font-size:14px;' height='20px;'>Email : ".$email."</td></tr>
<tr> <td colspan='3' style='padding-left:10px; font-family:Arial, Helvetica, sans-serif; font-size:14px;' height='20px;'>Age : ".$age."</td><td colspan='3' style='padding-left:10px; font-family:Arial, Helvetica, sans-serif; font-size:14px;' height='20px;'>Date : ".$dt."</td></tr>
<tr><td colspan='3' style='padding-left:10px; font-family:Arial, Helvetica, sans-serif; font-size:14px;' height='20px;'>Gender : ".$gender."</td><td colspan='3' style='padding-left:10px; font-family:Arial, Helvetica, sans-serif; font-size:14px;' height='20px;'>Mobile : ".$mob."</td></tr>
<tr><td colspan='3' style='padding-left:10px; font-family:Arial, Helvetica, sans-serif; font-size:14px;' height='20px;'>Center : ".$lname."</td><td colspan='3' style='padding-left:10px; font-family:Arial, Helvetica, sans-serif; font-size:14px;' height='20px;'>History : ".$history."</td></tr>
<tr><td colspan='3' style='padding-left:10px; font-family:Arial, Helvetica, sans-serif; font-size:14px;' height='20px;'>Address : ".$adrs."</td></tr></table></td></tr></table></td></tr>
<tr><td colspan='3'> </td></tr>
<tr><td><table width='98%'>
<tr><td colspan='3' align='center'><b>(DEEG) REPORT</b></td></tr>
<tr><td colspan='3'> </td></tr>
<tr><td colspan='3'><b>Clinical Interpretation :</b></td></tr>
<tr><td colspan='3' align='justify'> ".$clinic."</td></tr><br/>
<tr><td colspan='3'><b>Report :</b></td></tr>
<tr><td colspan='3' align='justify'> ".$report."</td></tr><br/>
<tr><td colspan='3'><b>EKG :</b></td></tr>
<tr><td colspan='3' align='justify'> ".$sumry."</td></tr><br/>
<tr><td colspan='3'><b>Activation Procedures :</b></td></tr>
<tr><td colspan='3' align='justify'> ".$act."</td></tr><br/>
<tr><td colspan='3'><b>Sleep :</b></td></tr>
<tr><td colspan='3' align='justify'> ".$sleep."</td></tr></table></td></tr>
</table></div>";
$headers = "From: $lemail";
$semi_rand = md5(time());
$headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";
$message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/html; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n";
foreach($_FILES as $userfile){
// store the file information to variables for easier access
$tmp_name = $userfile['tmp_name'];
$type = $userfile['type'];
$name = $userfile['name'];
$size = $userfile['size'];
if (file_exists($tmp_name)){
// check to make sure that it is an uploaded file and not a system file
if(is_uploaded_file($tmp_name)){
// open the file for a binary read
$file = fopen($tmp_name,'rb');
// read the file content into a variable
$data = fread($file,filesize($tmp_name));
// close the file
fclose($file);
// now we encode it and split it into acceptable length lines
$data = chunk_split(base64_encode($data));
}
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$type};\n" .
" name=\"{$name}\"\n" .
"Content-Disposition: attachment;\n" .
" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n";
}
}
// preparing attachments
// send
$message .= "--{$mime_boundary}--\n";
$ok = #mail($to, $subject, $message, $headers);
The above code sends mail without attaching the files and also shows a warning
Warning: file_exists() expects parameter 1 to be string, array given in ..my file
Please help me to find the issue. i used the same code in another project and it worked well but the only difference is that in that project i used 4 separate file upload inputs but in here i can't use like that.
Edit
After i used the swiftmailer i got these errors
Warning: basename() expects parameter 1 to be string, array given in C:\wamp\www\php\Teleneurology\swiftmailer-master\lib\classes\Swift\Mime\Attachment.php on line 139
Warning: strrpos() expects parameter 1 to be string, array given in C:\wamp\www\php\Teleneurology\swiftmailer-master\lib\classes\Swift\Mime\Attachment.php on line 143
The ouptut of var_dump($message) is:
string(2945) "This is a multi-part message in MIME format. --==Multipart_Boundary_x65d975657f4969833a0b685447467ab3x Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: 7bit
Hi ,
A new report
Details are:
Name : Email :
Age : Date : 21/10/2014
Gender : Mobile :
Center : History :
Address :
DIGITAL ELECTROENCEPHALOGRAPHY (DEEG) REPORT
Clinical Interpretation :
Select
Report :
Select
EKG :
Select
Activation Procedures :
Select
Sleep Record :
Select
--==Multipart_Boundary_x65d975657f4969833a0b685447467ab3x-- "
$_FILES is as multi level array. If you would echo print_r($_FILES);, you would see the problem.
Try to change:
foreach($_FILES as $userfile){
$tmp_name = $userfile['tmp_name'];
$type = $userfile['type'];
$name = $userfile['name'];
$size = $userfile['size'];
to:
foreach ($_FILES['files']['name'] as $index => $name) {
$tmp_name = $_FILES['files']['tmp_name'][$index];
$type = $_FILES['files']['type'][$index];
$size = $_FILES['files']['size'][$index];

Problems sending html email in php

I'm trying to send an email to myself that has a layout and images. What I'm I doing wrong?
<?php
$message = $_POST['message'];
$emailsubject = 'site.com';
$webMaster = 'email#site.com';
$body = "
<html>
<body bgcolor=\"e7e7e7\">
<style type=\"text/css\">
#body {margin: auto;border: 0;padding: 0;font-family: Georgia, 'Times New Roman', Times, serif;font-size: 12px;}
#emailHeader {width: 500px;height: 131px;background: url(http://www.site.com/images/image.gif) no-repeat;}
#emailContent {width: 500px;background: url(http://www.site.com/images/image2.gif) repeat-y;text-align: left;padding: 0 33px 0 6px;}
#emailFooter {width: 500px;height: 34px;background: url(http://www.site.com/images/image3.gif) no-repeat;}
</style>
<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
<td valign=\"top\" align=\"center\">
<table width=\"500\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
<td id=\"emailHeader\"></td>
</tr>
<tr>
<td id=\"emailContent\">
content $message
</td>
</tr>
<tr>
<td id=\"emailFooter\"></td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>"
$headers .= "Content-type: text/html\r\n";
$success = mail($webMaster, $emailsubject, $body, $headers);
if ($success) {
echo "Your message was sent.";
}
else{
echo "There was a error.";
}
?>
You should use phpmailer instead of PHP's mail()-Function. It allows you to easily send HTML-Mails.
Besides that you can try to validate your HTML-Code to be compatible for emailing.
Best wishes,
Fabian
You have an error in your code:
WRONG
$headers .= "Content-type: text/html\r\n";
RIGHT
$headers = "Content-type: text/html\r\n";
The .= throws a parse error in PHP unless you previously set $headers somewhere else.
It also may depend on the email client you are testing with. Be sure to check out http://www.email-standards.org/ to check what your email client supports.
You may also want to look into Zend_Mail from Zend Framework:
http://framework.zend.com/manual/en/zend.mail.html
Would make dealing with headers, formats, MIME, etc. easier.

Categories