sending attachment fails with php mailer function codeigniter - php

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;

Related

How send email from PHPMAILER without SMTP

Can anyone tell me, how send email from PHPMailer not using SMTP? This class includes the method isMail() and it should send an email using the mail() function instead SMTP. I'm use Xaamp. When I use SMTP server it's not working all.
My code:
$mail=new PHPMailer();
$mail->IsMail();
$mail->From = 'xxxx#email.com';
$body = "Test body message";
$mail->AddAddress("xxxx#emai.com", "John Doe");
$mail->Subject = "PHPMailer Test Subject via mail(), basic";
$mail->MsgHTML($body);
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
Send Method returns true and displays message that email has been sent?
The topic is old but for those who will read this.
Try to replace
$mail->isSMTP();
by
$mail->isSendMail();

PHPMailer "CharSet" incompatibility with "AltBody" and "AddEmbeddedImage" at the same time

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?

Send a file through email after Paypal payment is recieved

Is there any way to send a file in an email upon receiving a Paypal payment? Any tutorials to show how to do this? Any help would be much appreciated.
I would use SwiftMailer / attahching files if I were you upon receiving confirmation from PayPal.
Sending email is easy using the built in mail function in PHP. However, sending attachment is a whole other story.
I'd use a third party library like phpMailer
E.g. sending email with attachment:
require_once('path/to/class.phpmailer.php');
$mail = new PHPMailer(); // defaults to using php "mail()"
$body = file_get_contents('contents.html');
$body = eregi_replace("[\]",'',$body);
$mail->AddReplyTo("name#yourdomain.com","First Last");
$mail->SetFrom('name#yourdomain.com', 'First Last');
$mail->AddReplyTo("name#yourdomain.com","First Last");
$address = "whoto#otherdomain.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("images/phpmailer.gif"); // attachment
$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}

Script php : send mail using phpmailer

I'm trying to send a simple email using phpmailer.
I really have no idea if it's relevant since I'm just doing a php script, but I have apache2 & sendmail, apache2 running and sendmail include in the php.ini (sendmail_path=etc).
So here is my code :
<?php
$mail = new PHPMailer(); // defaults to using php "mail()"
$body = "<h1>Coucou</h1>";
$body = eregi_replace("[\]",'',$body);
$mail->AddReplyTo("totest#test.com","First Last");
$mail->SetFrom('fromtest#test.com', 'First Last');
$mail->AddReplyTo("totest2#test.com","First Last");
$address = "XXXX#gmail.com";
$mail->AddAddress($address, "XXXXX");
$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("./test.doc"); // attachment
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
So the thing is that my output is always "Message sent!", even if the script take a really long time to be executed (up to 10minutes !), but the mail never arrived to my mailbox (and I checked the spam folder).
Well I hope someone will have an explanation to that annoying problem!
Thank you anyway.
Regards,
Bdloul

Sending Plain text emails using PHPMailer

I have a problem sending plain text emails using PHPMailer.
I have text that I read from a text file and mail it to mail recipient via PHPMailer
When the recipient gets the actual email, the formatting of the mail is not like in the text file, everything is in one line, no new lines and tabs are included in the email that I send. Text wrapping is totally off.
Code:
$mail->ContentType = 'text/plain';
$mail->IsHTML(false);
$address = "test#test.com";
$mail->AddAddress($address, "John Doe");
$mail->SetFrom(EMAIL_TEST_FROM);
$mail->AddReplyTo(EMAIL_TEST_REPLY);
$mail->Subject = $action." REGISTRATION ".$formName.$tld;
$mail->From = EMAIL_TEST;
$mail->MsgHTML(file_get_contents($newFile));
if($mail->Send()){
return true;
}
You are setting $mail->MsgHTML() to a plain text message, and since whitespace formatting is ignored in HTML, you're getting an inline text.
I haven't used PHPMailer for a while, but from memory try:
$mail->Body = file_get_contents($newFile);
$mail->ContentType = 'text/plain';
$mail->IsHTML(false);
$address = "test#test.com";
$mail->AddAddress($address, "John Doe");
$mail->SetFrom(EMAIL_TEST_FROM);
$mail->AddReplyTo(EMAIL_TEST_REPLY);
$mail->Subject = $action." REGISTRATION ".$formName.$tld;
$mail->From = EMAIL_TEST;
// Very important: don't have lines for MsgHTML and AltBody
$mail->Body = file_get_contents($mailBodyTextFile);
// $mail->Body = $_POST["msg"]; //If using web mail form, use this line instead.
if($mail->Send()){
return true;
}
Try below code which works fine:
try {
$mail->AddAddress('jitpal#domain.com', 'Jit Pal');
$mail->SetFrom('testuser#domain.com', 'Test User');
$mail->Subject = "All machine's tests.";
$mail->Body = "All machine's tests working fine.";
$mail->Send();
echo "<br/>Message sent successfully...<br/><br/>\n";
} catch (phpmailerException $e) {
echo $e->errorMessage();
} catch (Exception $e) {
echo $e->getMessage();
}

Categories