I have this code where sending body in UTF-8 is not working:
<?php
require '../phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->CharSet = 'UTF-8';
$mail->setFrom('from#example.com', 'First Last');
$mail->addAddress('whoto#example.com', 'John Doe');
$mail->Subject = 'PHPMailer mail() test';
$mail->AltBody = 'This is a plain-text message body';
$mail->AddEmbeddedImage('img_00/Mailing_febrero2015_02.jpg', 'fondo', 'fondo.jpg');
$mail->Body = 'árbol';
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
But if I remove the "AltBody" or "AddEmbeddedImage" it sends correctly in UTF-8. Why this occurs (I have the last PHPMailer version)?
There is another correct way to add an alternative body and embedded image at the same time?
Related
This is my index.php file
Please suggest what is wrong with the below code that i am not receiving mails or if there is any other easy way of sending emails.
<?php
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPAuth=false;
$mail->SMTPSecure='tls';
$mail->Host='smtp.gmail.com';
$mail->port='587';
$mail->isHTML();
$mail->Username='demoXXXXX#gmail.com';
$mail->Password='XXXXXX';
$mail->SetFrom('no-reply#gmail.com');
$mail->Subject = "Subject Text";
$mail->Body = "<i>Mail body in HTML</i>";
$mail->addAddress("parkingston#gmail.com");
if(!$mail->send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent successfully";
}
?>
Include class.phpmailer.php & classes/class.smtp.php first .
<?php
require "autoload.php";
include "class.phpmailer.php"; // include the class name
include "class.smtp.php";
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPAuth=false;
$mail->SMTPSecure='tls';
$mail->Host='smtp.gmail.com';
$mail->port='587';
$mail->isHTML();
$mail->Username='demoXXXXX#gmail.com';
$mail->Password='XXXXXX';
$mail->SetFrom('no-reply#gmail.com');
$mail->Subject = "Subject Text";
$mail->Body = "<i>Mail body in HTML</i>";
$mail->addAddress("parkingston#gmail.com");
if(!$mail->send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent successfully";
}
?>
You can easily download this both file if you do not have it. Hope it will help you.
I am trying to send email from my website to my godaddy mail and zoho mail but its not working.
I tried it on my gmail account and its working fine.
I am using phpmailer.
MY CODE-
require_once "PHPMailerAutoload.php";
//PHPMailer Object
$mail = new PHPMailer;
//From email address and name
$mail->From = "test#deltware.com";
$mail->FromName = "Himanshu Mishra";
$mail->addAddress("my godaddy webmail"); //Recipient name is optional
//Send HTML or Plain Text email
$mail->isHTML(true);
$mail->Subject = "Subject Text";
$mail->Body = "<i>Mail body in HTML</i>";
$mail->AltBody = "This is the plain text version of the email content";
if(!$mail->send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent successfully";
}
Please help!!!!!
Your From syntax is wrong
Instead of
$mail->From = "test#deltware.com";
$mail->FromName = "Himanshu Mishra";
It should be
$mail->setFrom('test#deltware.com', 'Himanshu Mishra');
Check this link https://github.com/PHPMailer/PHPMailer
Im using phpMailer to send an image like attachment and a message in HTML. But the page show me that is not working.
include 'PHPMailer-master/class.phpmailer.php';
$mail = new PHPMailer();
$mail->From = 'someone#some.com';
$mail->FromName = 'someone';
$mail->AddAddress( 'someone#some2.com' );
$mail->Subject = 'Message Subject';
$mail->Body = "<h1>Test 1 of PHPMailer html</h1><p>This is a test</p>";
$mail->AltBody="This is text only alternative body.";
$mail->IsHTML(true);
$file_to_attach = '../images/logo.png';
$mail->AddAttachment( $file_to_attach , 'logo.png"' );
if(!$mail->Send())
echo "Error sending: " . $mail->ErrorInfo;;
else
echo "Letter is sent";
Using this code works perfectly to me send a message with HTML and an attachment.
<?php
require_once 'PHPMailer-master/class.phpmailer.php';
$mail = new PHPMailer(true);
try {
$mail->AddAddress('someone#some.com', 'a name');
$mail->SetFrom('someone2#some2.com', 'another name');
$mail->AddReplyTo('someone3#some3.com', 'another name');
$mail->Subject = 'PHPMailer Test';
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!';
$mail->IsHTML(true);
$mail->Body = "<h1>Test 1 of PHPMailer html</h1><p>This is a test</p>";
$mail->AddAttachment('../images/logo.png');
$mail->Send(); echo "Message Sent OK\n";
}
catch (phpmailerException $e) {
echo $e->errorMessage();
}
catch (Exception $e) {
echo $e->getMessage();
}
?>
You are using $email variable to new object PHPMailer but in line 8,9 and 14,15 you're using $mail.
$mail->AltBody="This is text only alternative body.";
$mail->IsHTML(true);
if(!$mail->Send())
echo "Error sending: " . $mail->ErrorInfo;
just use $email.
I see you are using
$file_to_attach = '../images/logo.png';
to get the name for the image file. However the file name is already set in:
$email->AddAttachment( $file_to_attach , 'logo.png"' );
Try putting the whole path in $email->AddAttachment(); like this $email->AddAttachment('../images/Logo.pgn');
Here I am trying to send email with an attachment, all codes are running fine but I didn't find any attachment along with the mail, but the same file is getting printed in hyper link that I had given with success message. I have used php mailer class in codeigniter.
public function sendmailto()
{
$this->load->library('phpmail');
$mail = new PHPMailer();
$body = "hello";
$mail->AddReplyTo("reply#mymail.com","First Last");
$mail->SetFrom('noname#mymail.com', 'First Last');
$mail->AddReplyTo("mail#mymail.com","First Last");
$address = "abcd#mymail.com";
$mail->AddAddress($address, "John Doe");
$mail->Subject = "PHPMailer Test Subject via mail(), basic";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$mail->AddAttachment("../../uploads/a.pdf"); // attachment
//$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
}
else {
echo "Message sent!<a href='../../uploads/a.pdf' >click</a>" ;
}
}
I think its path issue you can try this
$attachment = base_url().'/uploads/a.pdf';
$mail->AddAttachment($attachment); // attachment
I think you should change
$mail->MsgHTML();
to
$mail->Body;
EDIT:
The basic idea for sending email with PHPmailer was perfect. But I'm having issue attaching files (in different) format.
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "mail.domain.com"; // SMTP server
$mail->From = "frommail#domain.com";
$mail->FromName="fromname";
$mail->AddAddress("admin#domain.com");
$mail->IsHTML(true);
//for file attachments
$mail->AddAttachment($_FILES['uploaded_file']['tmp_name'], $_FILES['uploaded_file']['name']);
$mail->Subject = "First PHPMailer Message";
$mail->Body = "<b>Hi! <br><br> This is my first e-mail sent through PHPMailer.</b>";
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
//$mail->WordWrap = 50;
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}
I tried to display the sequence but not a help. Much appreciated for your time.