Send a file through email after Paypal payment is recieved - php

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!";
}

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();

sending attachment fails with php mailer function codeigniter

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;

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

PHPMailer With Attachment Never Received

I am tying to send an email with an attachment using phpmailer.
include_once('/home/site/PHPMailer/class.phpmailer.php');
$mail = new PHPMailer();
$body = $mail->getFile('contents.html');
$body = eregi_replace("[\]",'',$body);
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "smtp.free.fr"; // SMTP server
$mail->IsSendmail(); // telling the class to use SendMail transport
$mail->From = "name#sub.fr";
$mail->FromName = "name";
$mail->Subject = "subject";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$mail->AddAddress("sub#sub.net", "name");
$mail->AddAttachment("mylist.csv"); // attachment
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
I receive a "Message sent !" on execution, but no email is ever received.
It is very possible the user you sent the email to did not recieve it due to the fact a lot of mail providers such as AOL and Yahoo block massive amounts of Ip addresses related to email spam. So if the server you are running this php script from is on their blacklist the user will not even receive it to the spam folder.
Check your php email logs.
http://help.yahoo.com/l/us/yahoo/smallbusiness/webhosting/php/php-03.html
Also, if this is not the case, try making sure the file your trying to include exists, and you are passing the correct path to the file. Like #Waygood said, try seeing if it sends without the attachment.

I need to attach a file to an outbound email automatically...Help

I have one form (input.html) that's completed by people working in five different divisions of this business. When the form is submitted it posts to output.php.
Output.php does a number of things:
First it displays all of the input information to the screen as a completed form. (Just to show them their completed document).
It has also created a file called unique_file.html based on two of the input fields in input.html.
Next, output.php has sent an email to one of five email groups, based upon another input field selected in input.html.
Finally (for now), I need the unique_file.html to be an attachment to the email. That is my problem.
I have found scripts for uploading files, I have found many tutorials about uploading files, but I just want to attach the unique_file.html to my outgoing email and I am not seeing how that is done.
Can someone point me in the right direction as to where to start? I am certainly missing the boat on this one and I have probably seen it and not realized it.
If you can use the Zend_Framework you can easily attach file to an email i.e.
$mail = new Zend_Mail();
$at = new Zend_Mime_Part($myImage);
$at->type = 'image/gif';
$at->disposition = Zend_Mime::DISPOSITION_INLINE;
$at->encoding = Zend_Mime::ENCODING_8BIT;
$at->filename = 'test.gif';
$mail->addAttachment($at);
$mail->send();
see the documentation,
You should be able to attach a file also by using Mail_Mime pear package and the normal mail function.
But I think the solution using the Zend framework is much more straight forward.
Cheers.
I find PHPMailer best for this. An example from their site:
require_once('../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!";
}

Categories