php email function not sending attachment - php

I am trying to send a email with attachment my code is below let me know if i am doing missing something or doing something wrong
<?php
function mail_attachment( $filename, $path, $mailto, $from_mail, $from_name, $replyto, $subject, $message ) {
$file = $path. "/" .$filename;
$file_size = filesize($file);
$handle = fopen($file, "r");
$content = fread($handle, $file_size);
fclose($handle);
$content = chunk_split(base64_encode($content));
$separator = md5(uniqid(time()));
$eol = PHP_EOL;
$header = "From: ".$from_name." <usman_86#rocketmail.com>".$from_mail. $eol;
$header .= "Reply-To: ".$replyto.$eol;
$header .= "MIME-Version: 1.0".$eol;
$header .= "Content-Type: multipart/mixed; boundary=\"".$separator. "\"" . $eol . $eol;
$header .= "Content-Transfer-Encoding: 7bit" . $eol;
$header .= "--".$separator. $eol;
$header .= "Content-Type: text/plain; charset=\"iso-8859-1\"" . $eol;
$header .= "Content-Transfer-Encoding: 8bit" . $eol . $eol;
$header .= $message. $eol . $eol;
$header .= "--".$separator. $eol;
$header .= "Content-Type: application/octet-stream; name=\"".$filename. $eol; // use different content types here
$header .= "Content-Transfer-Encoding: base64".$eol;
$header .= "Content-Disposition: attachment; filename=\"".$filename. $eol;
$header .= $content. $eol;
$header .= "--".$separator."--";
ob_start(); //Turn on output buffering
if( mail( $mailto, $subject, "", $header ) ) {
echo "mail send ... OK"; // or use booleans here
} else {
echo "mail send ... ERROR!";
}
}
if( isset($_REQUEST['FindDealer']) ){
$my_file = "pdf.pdf";
$my_path = "/";
$my_name = " Find Dealer # flowsleeve";
$my_mail = "stifstone#gmail.com";
$my_replyto = "my_reply_to#flowsleeve.com";
$my_subject = "Find Dealer # flowsleeve";
$my_message = "Hallo,\r\ndoPlease find Attached PDF For Dealers";
mail_attachment( $my_file, $my_path, $my_mail, $my_name, $my_replyto, $my_subject, $my_message );
header("Location: index.php#section8");
exit();
}
?>

use $mail->addAttachment($path);
It is better to use this.
you can get phpmailer file from https://github.com/PHPMailer/PHPMailer
<?php
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'user#example.com'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('from#example.com', 'Mailer');
$mail->addAddress('joe#example.net', 'Joe User'); // Add a recipient
$mail->addAddress('ellen#example.com'); // Name is optional
$mail->addReplyTo('info#example.com', 'Information');
$mail->addCC('cc#example.com');
$mail->addBCC('bcc#example.com');
$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
?>

There is lots here to try to digest but the following line looks wrong.
$header = "From: ".$from_name." <usman_86#rocketmail.com>".$from_mail. $eol;
When resolved, this would appear as:
"From: my_reply_to#flowsleeve.com <usman_86#rocketmail.com>Find Dealer # flowsleeve\r\n"
The reply-to address is also wrong, see the full printout of the header to see what I mean.
Tip: To make it easier I'd suggest using variables that are named the
same as the parameters supplied to the function mail_attachment ~ I
keep having to count which parameter refers to which variable.
The entire header appears like this:
From: my_reply_to#flowsleeve.com <usman_86#rocketmail.com>Find Dealer # flowsleeve
Reply-To: Find Dealer # flowsleeve
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="2642aff44ba290c53e0574e15444e12f"
Content-Transfer-Encoding: 7bit
--2642aff44ba290c53e0574e15444e12f
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 8bit
--2642aff44ba290c53e0574e15444e12f
Content-Type: application/octet-stream; name="pdf.pdf
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="pdf.pdf
--2642aff44ba290c53e0574e15444e12f--
From previous experience of dealing with attachments the formatting is critical - it MUST be exactly right in terms of line endings or it will fail.
Some pointers that might help:
There should be only one new line before a boundary.
There should be 2 dashes only after the last boundary.
There are 2 places where Content-Transfer-Encoding needs to have a new line before.
Also, I forgot to mention that you call the function mail_attachment with 7 parameters yet the function takes 8 parameters. The one that appears to not be supplied in the function call is $from_mail

Related

php mail() function, headers issue, can not send an email

I know this is really common issue, but I have problem with headers. This function send email only when I send mail with $header2. In other cases I get fail echo. Does not working with $headers.
I don't know why it is happening, also it doesn't work with php.net default headers below:
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
Complete function:
function sendMail() {
$to = "mymail#gmail.com";
$subject = "This is subject";
$message = "<b>This is HTML message.</b>";
$message .= "<h1>This is headline.</h1>";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: Mary <mary#example.com>, Kelly <kelly#example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday#example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive#example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck#example.com' . "\r\n";
$header2 = "From:abc#somedomain.com \r\n";
$header2 = "Cc:afgh#somedomain.com \r\n";
$header2 .= "MIME-Version: 1.0\r\n";
$header2 .= "Content-type: text/html\r\n";
$retval = mail ($to, $subject, $message, $headers);
if( $retval == true ) {
echo "Message sent successfully...";
}else {
echo "Message could not be sent...";
}
}
Firstly, just get rid of this entire code block since there is no reference to your usage of the $headers2 variable. Do go over my answer in its entirety.
$header2 = "From:abc#somedomain.com \r\n";
$header2 = "Cc:afgh#somedomain.com \r\n";
// ^ BROKEN concatenate
$header2 .= "MIME-Version: 1.0\r\n";
$header2 .= "Content-type: text/html\r\n";
PHP is going over your entire code, regardless. And it contains a broken concatenate.
However, it's unclear as to what you want to do here and have obviously taken examples from the manual on mail() http://php.net/manual/en/function.mail.php then just blindly adding stuff in there.
Sidenote: The To: is already pre-determined as to where it should be sent to, so the use of To: in the headers isn't required.
function sendMail() {
$to = "mymail#gmail.com";
$subject = "This is subject";
$message = "<b>This is HTML message.</b>";
$message .= "<h1>This is headline.</h1>";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= "From:abc#somedomain.com \r\n";
$headers .= "Cc:afgh#somedomain.com \r\n";
$retval = mail ($to, $subject, $message, $headers);
if( $retval == true ) {
echo "Message sent successfully...";
}else {
echo "Message could not be sent...";
}
}
and if the goal here is to send 2 seperate mails, then you will need to use 2 seperate mail() functions and 2 different header variables.
Something to which you can consult, as per an answer I once gave for another question:
https://stackoverflow.com/a/18382062/1415724
Add error reporting to the top of your file(s) which will help find errors.
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Then the rest of your code
Sidenote: Displaying errors should only be done in staging, and never production.
Please stop using the php mail() function! My advice will be to use PHPMailer and sending the emails via SMTP.
Here is a small code snippet using PHPmailer:
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtpserver.com'; // Specify main SMTP server. If you dont have one us GMAL or mandrill
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'user#youremail.com'; // SMTP username
$mail->Password = 'pass'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('from#youremail.com', 'Mailer');
$mail->addAddress('joe#youremail.net', 'Joe User'); // Add a recipient
$mail->addAddress('ellen#youremail.com'); // Name is optional
$mail->addReplyTo('info#youremail.com', 'Information');
$mail->addCC('cc#youremail.com');
$mail->addBCC('bcc#youremail.com');
$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}

How to attach pdf in mail of html content in mail on form submit using php?

I want to attach a pdf file of html content when form submit.
Html form is made with css so pdf is generated with css.
generated pdf has attached in mail on form submit.
you can use this function to send email. I hope you have created file to attach so you can pass file name i fuction.
function mail_attachment($filename, $path, $mailto, $from_mail, $from_name, $replyto, $subject, $message) {
$file = $path.$filename;
$file_size = filesize($file);
$handle = fopen($file, "r");
$content = fread($handle, $file_size);
fclose($handle);
$content = chunk_split(base64_encode($content));
$uid = md5(uniqid(time()));
$header = "From: ".$from_name." <".$from_mail.">\r\n";
$header .= "Reply-To: ".$replyto."\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
$header .= "This is a multi-part message in MIME format.\r\n";
$header .= "--".$uid."\r\n";
$header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
$header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$header .= $message."\r\n\r\n";
$header .= "--".$uid."\r\n";
$header .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n";
$header .= "Content-Transfer-Encoding: base64\r\n";
$header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
$header .= $content."\r\n\r\n";
$header .= "--".$uid."--";
// Messages for testing only, nobody will see them unless this script URL is visited manually
if (mail($mailto, $subject, "", $header)) {
echo "Message sent!";
} else {
echo "ERROR sending message.";
}
}
If you are using phpmailer fuction so this code will help you to send pdf file:
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "smtp.server.net";
$mail->SMTPAuth = true;
$mail->Username = "username#domain.com";
$mail->Password = "password1";
$mail->From = "username#domain.com";
$mail->FromName = "Software something";
$mail->AddAddress("targetguy#domain.com", "Target Guy");
$mail->AddReplyTo("username#domain.com", "Software Simian");
$mail->WordWrap = 50;
$mail->IsHTML(true);
$mail->Subject = "Subject";
$mail->Body = "Message";
$mail->AltBody = strip_tags("Message:);
$mail->AddAttachment("filename.pdf");
if(!$mail->Send()){
$resultstatus = 'Failed';
}

send attachment in php mail

I want to send a file in a link which want to get download.I linked the path of the file in anchor tag.But I doesn't get downloaded.That file gets open in next page without downloading.I want to download a file in anchor tag.I want to download in from a link instead of attachment.
move_uploaded_file($_FILES['resume'] ['tmp_name'],'resume/'.$_FILES['resume'][name]);
$url='resume/'.$_FILES['resume']['name'];
$from = $email;
$to="websoftbms#gmail.com";
$headers1 = "From: $from\n";
$headers = "From: $email\r\n";
$headers .= "Reply-To: websoftbms#gmail.com\r\n";
$headers .= "Return-Path: sathurka.mca#gmail.com\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$body = "
Hello,<br>
This mail is sent via blumounts.com<br>
Name:$user<br>
Email:$email<br>
Subject:$subject<br>
message:$message<br>
resume :<a href='//domain.com/website/$url' download>Download</a> <br>
";
$body.="<br>
Thank you,<br>
$user<br>";
if( $sentmail = mail( $to,"Sent via career form.", $body, $headers ))
{
echo '<script>
window.alert("Email sent");
window.reload();
</script>';
}
Try this...
The mail() function doesn’t support attachment or HTML mail by default. You need to use different headers and MIME mail parts to make this possible. Many shared hosting providers doesn’t allow the usage of this function and it might be disabled.
Normally you will pass three values to the mail() function plus some headers. In the example below I skip the value for the message value, because the message is defined as a MIME part together with the attachment.
<?php
function mail_attachment($filename, $path, $mailto, $from_mail, $from_name, $replyto, $subject, $message) {
$file = $path.$filename;
$file_size = filesize($file);
$handle = fopen($file, "r");
$content = fread($handle, $file_size);
fclose($handle);
$content = chunk_split(base64_encode($content));
$uid = md5(uniqid(time()));
$header = "From: ".$from_name." <".$from_mail.">\r\n";
$header .= "Reply-To: ".$replyto."\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
$header .= "This is a multi-part message in MIME format.\r\n";
$header .= "--".$uid."\r\n";
$header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
$header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$header .= $message."\r\n\r\n";
$header .= "--".$uid."\r\n";
$header .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n"; // use different content types here
$header .= "Content-Transfer-Encoding: base64\r\n";
$header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
$header .= $content."\r\n\r\n";
$header .= "--".$uid."--";
if (mail($mailto, $subject, "", $header)) {
echo "mail send ... OK"; // or use booleans here
} else {
echo "mail send ... ERROR!";
}
}
$my_file = "file.extension";
$my_path = "/your_path/to_the_attachment/";
$my_name = "Olaf Lederer";
$my_mail = "my#mail.com";
$my_replyto = "my_reply_to#mail.net";
$my_subject = "This is a mail with attachment.";
$my_message = "Hallo,\r\ndo you like this script? I hope it will help.\r\n\r\ngr. Olaf";
mail_attachment($my_file, $my_path, "recipient#mail.org", $my_mail, $my_name, $my_replyto, $my_subject, $my_message);
Download PHPMailer from here
Create a PHP test file :
<?php
include_once("phpmailer/class.phpmailer.php");
$mail = new PHPMailer () ;
$mail->IsSMTP () ;
// UPDATED CODE -->>
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->Username = // your gmail address "user3386779#gmail.com"
$mail->Password = // your gmail password "passwordUser3386779!"
// <<-- UPDATED CODE
// if you want to format your message body wih HTML Tags
$mail->IsHTML ( true ) ;
$mail->From = $sender_s ;
$mail->Subject = $subject_s ;
$mail->Body = $mail_body_lt ;
// -- Rc : you can loop to add multiple receivers ....
$mail->AddAddress (trim($rc_s));
// -- Cc : you can loop to add multiple receivers ....
$mail->AddCC (trim($cc_s));
// -- Attach file
if (file_exists($attached_files_s) !== TRUE) {
sprintf("file: %s doesn't exist.", $attached_files_s);
}
else {
// Attachement: you can loop to attach multiple files ....
$mail->AddAttachment($attached_files_s);
}
// -- sending mail and catch errors
if ( ! $mail->send () ) {
return $mail->ErrorInfo ;
}
Instead of linking to the real file, make a link to a PHP page with the filename as an argument, and add this header :
// $mimetype is the mimetype of your file.
// You may force it, or use finfo functions to get it :
// http://php.net/manual/fr/function.finfo-file.php
header('Content-type: '.$mimetype);
header('Content-Disposition: attachment; filename="'.$file.'"');
You may of course have to adapt the paths.

How to send multiple attachment in single mail in php

I would like to know about attaching multiple attachment in single mail and send . Please refer my following oode. In this only one file is getting attached. That is second file. First file is not at all considering for attaching. But file is being created properly in the path specified.
$filename=array($filenamee1 ,$filenamee2);
for($x=0;$x<count($filename);$x++){
echo $path.$filename[$x];
$file = $path.$filename[$x];
$file_size = filesize($file);
$handle = fopen($file, "r");
$content = fread($handle, $file_size);
fclose($handle);
$content = chunk_split(base64_encode($content));
$uid = md5(uniqid(time()));
$name = basename($file);
$header = "From: ".$from_name." <".$from_mail.">\r\n";
$header .= "cc: ".$mailtoCC."\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
$header .= "This is a multi-part message in MIME format.\r\n";
$header .= "--".$uid."\r\n";
$header .= "Content-type:text/html; charset=iso-8859-1\r\n";
$header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$header .= $message."\r\n\r\n";
$header .= "--".$uid."\r\n";
$header .= "Content-Type: application/octet-stream; name=\"".$filename[$x]."\"\r\n";
$header .= "Content-Transfer-Encoding: base64\r\n";
$header .= "Content-Disposition: attachment; filename=\"".$filename[$x]."\"\r\n\r\n";
$header .= $content."\r\n\r\n";
$header .= "--".$uid."--";
}
if (mail($mailto, $subject, "", $header)) {
echo "<br>mail sent Successfully... OK";
} else {
echo "<br>mail send ... ERROR!";
}
Following the reusability principles, you can use https://github.com/PHPMailer/PHPMailer
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup server
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'jswan'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
$mail->From = 'from#example.com';
$mail->FromName = 'Mailer';
$mail->addAddress('josh#example.net', 'Josh Adams'); // Add a recipient
$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
echo 'Message has been sent';
Source: How to attach two or multiple files and send mail in PHP
This is what I came up with for multiple files with form file name userfile:
for($ct=0;$ct<count($_FILES['userfile']['tmp_name']);$ct++)
{
$uploadfile = tempnam(sys_get_temp_dir(), sha1($_FILES['userfile']['name'][$ct]));
$filename =$_FILES['userfile']['name'][$ct];
if (move_uploaded_file($_FILES['userfile']['tmp_name'][$ct], $uploadfile)) {
$mail->addAttachment($uploadfile, $filename);
}
}
if ($mail->send()) {
echo "Sent";
} else {
echo "Mailer Error: " . $mail->ErrorInfo;
}
For those who want to send multiple files using phpMailer and input file multiple.
I joined and used the above two codes of #Rishi and #Matheno to achieve this result that dinamically add attachments selecteds by user.
On your input file name remember to put brackets:
<input type="file" multiple="multiple" name="attach_file[]" />
On your php send file:
Instead of:
$mail->addAttachment('/var/tmp/file.tar.gz');
Use:
for($ct=0;$ct<count($_FILES['attach_file']['tmp_name']);$ct++){
$mail->AddAttachment($_FILES['attach_file']['tmp_name'][$ct],$_FILES['attach_file']['name'][$ct]);
}

send email in php with attachment

i have use this code in php mail send with attachment. I am using the Apache http server with wamp.
<?php $to = 'santosh_091020#rediffmail.com';
// Declaring the necessary variables for mail sending :
$subject = 'Testing sendmail.exe';
$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$mob = $_REQUEST['mob'] ;
$msg = $_REQUEST['msg'] ;
$message = ' santosh enquire \n\nName: '.$name.' \n Email:'. $email.' \n Mobile:'. $mob.' \n Message: '.$msg.' \n ';
// Declaration of the attributes for attachment.
$upload_name=$_FILES["upload"]["name"];
$upload_type=$_FILES["upload"]["type"];
$upload_size=$_FILES["upload"]["size"];
$upload_temp=$_FILES["upload"]["tmp_name"];
$fp = fopen($upload_temp, "rb");
$file = fread($fp, $upload_size);
fclose($fp);
$file = chunk_split(base64_encode($file));
$num = md5(time());
// Defining the contents of the header.
$headers = "From: ".$email. "\r\n" . "CC: santosh#creativecrows.com" ;
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed; ";
$headers .= "boundary=".$num."\r\n";
$headers .= "--$num\r\n";
//$headers .= "Message-ID: <".gettimeofday()." TheSystem#".$_SERVER['SERVER_NAME'].">\r\n";
$headers .= "X-Mailer: PHP v".phpversion()."\r\n";
$headers .= "Content-Type: text/html; charset=iso-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: 8bit\r\n";
$headers .= "".$message."\n";
$headers .= "--".$num."\n";
$headers .= "Content-Type:".$upload_type." ";
$headers .= "name=\"".$upload_name."\"r\n";
$headers .= "Content-Transfer-Encoding: base64\r\n";
$headers .= "Content-Disposition: attachment; ";
$headers .= "filename=\"".$upload_name."\"\r\n\n";
$headers .= "".$file."\r\n";
$headers .= "--".$num."--";
//$data = chunk_split(base64_encode($data));
// sending the mail.
if(mail($to, $subject, $message, $headers))
{
echo "Email sent";
send();
}
else
{
echo "Email sending failed";
}
//send mail in client
function send()
{
$email = $_REQUEST['email'] ;
$name = $_REQUEST['name'] ;
$to= trim($email);
$subject = 'thanx';
$message = '<html><head><title>HTML email</title></head>
<body style="background-color:#000099;"><p style="color:#000099;">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>';$headers1 = 'MIME-Version: 1.0' . "\r\n";
$headers1.= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers1.= "From: ".$email;
if(mail($to, $subject, $message,$headers1))
{
echo "Email sent";
}
else
{
echo "Email sending failed";
echo $to;
echo $subject;
echo $message;
}
}
?>
but i got the following error;
Delivery to the following recipient failed permanently:
1.0#localhost
Technical details of permanent failure:
DNS Error: Domain name not found.
please help me. Thnx in advance.
Check this URL,
seems your header info is not absolute
http://webcheatsheet.com/php/send_email_text_html_attachment.php
$mail = new PHPMailer;
$mail->IsSMTP(); // Set mailer to use SMTP
$mail->Host = ''; // Specify main and backup server
$mail->Port = '';
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = ''; // SMTP username
$mail->Password = ''; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
$mail->From = '';
$mail->FromName = '';
$mail->AddAddress($row['client_email'], ''); // Add a recipient
$mail->AddReplyTo('', 'Information');
$mail->AddCC('cc#example.com');
$mail->AddBCC('bcc#example.com');
$mail->WordWrap = 50;
// Set word wrap to 50 characters
$mail->AddAttachment('kurtacompany/techreporting/upload/"'.$row['file1'].'"'); // Add attachments
$mail->IsHTML(true); // Set email format to HTML
$mail->Subject = '';
$mail->Body = '<p>type whatever you want</p>';
if(!$mail->Send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
echo 'Message has been sent';

Categories