multiple file uploaded is not attaching to mail - php

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

Related

unable to receive email through contact form here is my code

I am unable to receive email.here is my code.and i am trying to find my error but i am unable to find.so plzz anybody help me to solve this one.i am doubtful too about my code.here is my code which i have in my php file.my mail()
functions return true and i have modified my xamp config files.
<?php
require("connection.php");
?>
<?php
if(isset($_REQUEST))
{
$first = $_REQUEST['firstname'];
$middle = $_REQUEST['middlename'];
$last = $_REQUEST['lastname'];
$email = $_REQUEST['email'];
$phone = $_REQUEST['phone'];
$message =$_REQUEST['message'];
$query=" INSERT INTO `contact`(`id`,`first-name`, `middle-name`, `last-name`, `email`, `phone`, `message`) VALUES ('','$first','$middle','$last','$email','$phone','$message')";
$result = mysql_query($query);
if($result)
{
echo "data entered";
}
else
{
echo "data is not entered";
}
$to = "mehmood.asif31#gmail.com";
$subject = "Message From Contact Us Page";
$headers = "From:mehmood.asif31#gmail.com \r\n";
$headers .= "Bcc:mehmood.asif31#gmail.com \r\n";
$message = '<div style="margin:0 auto; padding:0px; width:800px">
<p style="font:bold 28px Arial, Helvetica, sans-serifl ; color:#006699; padding:0 0 0px 0; ">Feedback Message</p>
<div style=" margin:0 0 20px 0; font-family:Arial, Helvetica, sans-serif; font-size:15px; padding:10px; margin:0px; line-height:22px;">
<table>
<tr>
<td><strong>Name:</strong></td>
<td>'.$first.'</td>
</tr>
<tr>
<td><strong>Email ID:</strong></td>
<td>'.$email.'</td>
</tr>
<tr>
<td><strong>Phone No:</strong></td>
<td>'.$phone.'</td>
</tr>
<tr>
<td><strong>Message:</strong></td>
<td>'.$message.'</td>
</tr>
</table>
</div>
</div>';
//echo $message; exit;
mail($to, $subject, $message, $headers);
unset($_POST);
}
?>

How to add html table to database and save

I am new to PHP.I had created the table with the button "save Form".I am unable to save the table data to database.When I click on the "save form" button no action is performing.Please help me.
This is my Form.phtml
<div>
<b> Hello <?php echo $_POST["name"]; ?>!</b><br>
<b>Email :</b> <?php echo $_POST["email"]; ?>.<br>
<b>Gender :</b> <?php echo $_POST["gender"]; ?>.<br>
<b>Birthday :</b>
<?php
$day = $_POST['day'];
$month = $_POST['month'];
$year = $_POST['year'];
$date = $day."-".$month."-".$year;
$myDate = date("d F Y", strtotime($date));
echo $myDate;
?>
</div>
<form action="sendmail.php" method="post" id="vaccination-form">
<div>
<table border="1" style="width:100%">
<tr>
<th id= "sno" style="font-family: sans-serif; font-size: 100%; font-weight: bold;" class="bg-color" width="5%">S.No</th>
<th id= "vaccine" style="font-family: sans-serif; font-size: 100%; font-weight: bold;" class="bg-color center" width="32%">Vaccine</th>
<th id="decsription" style="font-family: sans-serif; font-size: 100%; font-weight: bold;">Description</th>
<th id="duedate" style="font-family: sans-serif; font-size: 100%; font-weight: bold;" class ="bg-color" width="15%">Due Date</th>
</tr>
<tr>
<td>1</td>
<tr>
</table>
</form>
<div>
<button type="submit" name="submit" style="margin-top: 1cm;"title="<?php echo $this->__('Save Form') ?>" value="submit "class="button"><span><span><?php echo $this->__('Save Form')?></span> </span> </button>
</div>
sendmail.php
<?php
//due dates
$myDate=$_POST['myDate'];
$dueDate=$_POST['dueDate'];
$rodueDate=$_POST['rodueDate'];
$didueDate=$_POST['didueDate'];
$pdueDate=$_POST['pdueDate'];
$hadueDate=$_POST['hadueDate'];
$indueDate=$_POST['indueDate'];
$idueDate=$_POST['idueDate'];
$rdueDate=$_POST['rdueDate'];
$vdueDate=$_POST['vdueDate'];
$tdueDate=$_POST['tdueDate'];
$hdueDate=$_POST['hdueDate'];
$mdueDate=$_POST['mdueDate'];
$email=$_POST['email'];
$name=$_POST['name'];
$to=$email;
$subject= "Vaccination Schedule For ".$name;
$message=
'
</table>';
// 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: someone#example.com" . "\r\n" ;
if( mail($to, $subject, $message, $headers))
{
echo 'Your mail has been sent successfully';
}
else
{
echo 'Unable to send email. Please try again.';
}
?>
Show us your sendmail.php.
Mainly you need to get POST variables into sendmail.php and then create a insert sql statement with data you got from POST variables..
How to do stuff above is totaly up to you, there are many ways, but we cannot tell you since you didnt give us enough info about your system.
I do not think the right thing to do , but still think you need to put the submit button between tags

Mail message and attachment in 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

How make a submit php that will send image (from user upload) via email?

I need help generating form to email, i'll try many outhere but no one matched i need. I have a form i've got from Bell Online Mailer, but this script doesnt allow image to send... So i modif a little form code and now i already had an upload form. And now what kind of function or php i mustly add to display it as an image (NOT ATTACHED) corectly inside the form message..
here is the code
<?php
/*
BELLonline PHP MAILER SCRIPT v1.5
Copyright 2006 Gavin Bell
http://www.bellonline.co.uk
gavin#bellonline.co.uk
Set up an email form on your website within minutes - see readme.txt for installation.
*/
extract($_POST);
if (!file_exists("config.php"))
{
$host = $_SERVER[HTTP_HOST ];
$path = pathinfo($_SERVER['PHP_SELF']); $file_path = $path['dirname']; print "<h1>BELLonline PHP mailer script</h1> <h2>There is a problem with your PHP mailer script installation</h2> <p>The config.php file seems to be missing!</p> <p>For this script to work, you need to upload the config.php file that came with the download of the BELLonline PHP mailer script.</p> <p>The file must be in the following directory of your website:</p> <p>$host<span style=\"font-weight: bold; font-size: 150%;\">$file_path/</span></p> <p>If you need help installing the script, then feel free to email me at gavin#bellonline.co.uk</p>"; exit; } include "config.php";
if ($sendto_email == "changeme#example.com") { print "<h1>BELLonline PHP mailer script</h1> <h2>Installation nearly complete!</h2> <p>Thank you for downloading the free PHP mailer script from BELLonline web services. </p> <p>To start using the script, open config.php in a text editor and change the <b>$sendto_email</b> variable to your email address.</p> <p>If you did not get a config.php file with this script, then go to the PHP mailer script page and download the full script.</p> <p>If you need help installing the script, then feel free to email me at gavin#bellonline.co.uk</p>"; exit; } if (empty ($senders_name)) { $error = "1"; $info_error .= $lang_noname . "<br>"; } if (empty ($senders_email)) { $error
= "1"; $info_error .= $lang_noemail . "<br>"; } if (empty ($mail_subject)) { $error = "1"; $info_error .= $lang_nosubject . "<br>"; } if (empty ($mail_message)) { $error = "1"; $info_error .= $lang_nomessage . "<br>"; } if (!eregi("^[A-Z0-9._%-]+#[A-Z0-9._%-]+\.[A-Z]{2,6}$", $senders_email)) { $error = "1"; $info_error .= $lang_invalidemail . "<br>"; } if (empty ($security_code)) { $error = "1"; $info_error .= $lang_nocode . "<br>"; } elseif ($security_code != $randomness) { $error = "1"; $info_error .= $lang_wrongcode . "<br>"; } if ($showlink != "no") { $link = "<br><span style=\"font-size: 10px;\">Powered by BELLonline PHP mailer script</span>"; } if ($error == "1") { $info_notice = "<span style=\"color: " . $error_colour . "; font-weight: bold;\">" . $lang_error . "</span><br>"; if (empty ($submit)) { $info_error = ""; $info_notice = $lang_notice; }
function Random() { $chars = "ABCDEFGHJKLMNPQRSTUVWZYZ23456789"; srand((double)microtime()*1000000); $i = 0; $pass = '' ; while ($i <= 4) { $num = rand() % 32; $tmp = substr($chars, $num, 1); $pass = $pass . $tmp; $i++; } return $pass; } $random_code = Random(); $mail_message = stripslashes($mail_message);
print "<form name=\"BELLonline_email\" enctype=\"multipart/form-data\" method=\"post\" style=\"margin: 0;\" action=\"\"> <table border=\"0\" cellspacing=\"2\" cellpadding=\"2\">
<tr align=\"$title_align\" valign=\"top\">
<td colspan=\"2\"><span style=\"$title_css\">$lang_title</span></td>
</tr>
<tr align=\"left\" valign=\"top\">
<td colspan=\"2\">$info_notice$info_error</td>
</tr>
<tr valign=\"top\">
<td align=\"right\">$lang_name</td>
<td align=\"left\"><input name=\"senders_name\" type=\"text\" class=\"mailform_input\" id=\"senders_name\" style=\"width: $input_width;\" value=\"$senders_name\" maxlength=\"32\"></td>
</tr>
<tr valign=\"top\">
<td width=\"100\" align=\"right\">$lang_youremail</td>
<td align=\"left\"><input name=\"senders_email\" type=\"text\" class=\"mailform_input\" id=\"senders_email\" style=\"width: $input_width;\" value=\"$senders_email\" maxlength=\"64\"></td>
</tr>
<tr valign=\"top\">
<td width=\"100\" align=\"right\">$lang_subject</td>
<td align=\"left\"><input name=\"mail_subject\" type=\"text\" class=\"mailform_input\" id=\"mail_subject\" style=\"width: $input_width;\" value=\"$mail_subject\" maxlength=\"64\"></td>
</tr>
<tr valign=\"top\">
<td width=\"100\" align=\"right\">$lang_message</td>
<td align=\"left\"><textarea name=\"mail_message\" cols=\"36\" rows=\"5\" style=\"width: $input_width;\" class=\"mailform_input\">$mail_message</textarea></td>
</tr>
<tr valign=\"top\">
<td width=\"100\" align=\"right\">$lang_image</td>
<td align=\"left\"><input name=\"mail_image\" size=\"10\" type=\"file\" class=\"mailform_input\" id=\"mail_image\" value=\"$mail_image\" maxlength=\"64\"></td>
</tr>
<tr align=\"left\" valign=\"top\">
<td width=\"100\">$lang_confirmation</td>
<td><input name=\"security_code\" type=\"text\" id=\"security_code\" size=\"5\">
<b>$random_code</b></td>
</tr>
<tr valign=\"top\">
<td colspan=\"2\" align=\"right\"><input name=\"randomness\" type=\"hidden\" id=\"randomness\" value=\"$random_code\">
<input name=\"submit\" type=\"submit\" id=\"submit\" value=\"$lang_submit\" class=\"mailform_button\"></td>
</tr> </table> </form>"; } else {
if ($checkdomain == "yes") { $sender_domain = substr($senders_email, (strpos($senders_email, '#')) +1); $recipient_domain = substr($sendto_email, (strpos($sendto_email, '#')) +1); if ($sender_domain == $recipient_domain) { print "Sorry, you cannot send messages from this domain ($sender_domain)"; exit; } }
$info_notice = $lang_sent; $mail_message = stripslashes($mail_message); $mail_image = $_POST['mail_image']; $content = $mail_image . $mail_message . '<p> Oleh ' . $senders_name . ', hubungi ' . $senders_email . ' </p>'; $senders_email = preg_replace("/[^a-zA-Z0-9s.#-_]/", "-", $senders_email); $from = $senders_email; $senders_name = preg_replace("/[^a-zA-Z0-9s]/", " ", $senders_name); $headers = "From: $senders_name <$senders_email> \r\n"; $headers .= "X-Mailer: BELLonline.co.uk PHP mailer \r\n"; $result = sendmail($sendto_email, $mail_subject, $content, $from);
print " <table border=\"0\" cellspacing=\"2\" cellpadding=\"2\">
<tr align=\"$title_align\" valign=\"top\">
<td colspan=\"2\"><span style=\"$title_css\">$lang_title</span></td>
</tr>
<tr align=\"$title_align\" valign=\"top\">
<td colspan=\"2\">$info_notice</td>
</tr>
<tr valign=\"top\">
<td width=\"100\" align=\"right\">$lang_name</td>
<td align=\"left\"><b>$senders_name</b></td>
</tr>
<tr valign=\"top\">
<td width=\"100\" align=\"right\">$lang_youremail</td>
<td align=\"left\"><b>$senders_email</b></td>
</tr>
<tr valign=\"top\">
<td width=\"100\" align=\"right\">$lang_subject</td>
<td align=\"left\"><b>$mail_subject</b></td>
</tr>
<tr valign=\"top\">
<td width=\"100\" align=\"right\">$lang_message</td>
<td align=\"left\"><b>$mail_message</b></td>
</tr>
</table>";
}
//Simple mail function with HTML header
function sendmail($sendto_email, $mail_subject, $content, $from) {
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: ' . $from . "\r\n";
$result = mail($sendto_email, $mail_subject, $content, $headers);
if ($result) return 1;
else return 0;
}
?>
You can easily solve it using PHP upload or an image uploader (I'm using Plupload at the moment) and PHP Mailer to send the email. As you mentioned not to intend sending the image as an attachment, in PHP Mailer, you just have to set an html message with the image inside it.

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