我之前使用过IP()邮件功能和IPN,它运行得很好。
$iemail = $_POST['payer_email'];
$to = $iemail;
$subject = 'somethinghere';
$message = '
Thank you for your purchase
$headers = 'From: support@mydomain.org' . "\r\n" .
'Reply-To: support@mydomain.org' . "\r\n" ;
//mail($to, $subject, $message, $headers);
这很好用,但我想将几个文件附加到我的电子邮箱中。
所以$ iemail是mysql数据库中的一个表。
所以这些是我尝试使用PHPMailer的方式:
require_once('class.phpmailer.php');
$iemail = $_POST['payer_email'];
$mail = new PHPMailer(); // defaults to using php "mail()"
$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 = $iemail;
$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("something.pdf"); // attachment
问题是我没有收到任何包含此脚本的电子邮件。我做错了什么我确定但我不知道是什么。你能帮助我吗?
谢谢。
以下是我的全部代码:
<?php
//Change these with your information
$paypalmode = 'sandbox'; //Sandbox for testing or empty ''
$dbusername = 'ipn'; //db username
$dbpassword = 'password'; //db password
$dbhost = 'mysqlhost'; //db host
$dbname = 'ibn_table'; //db name
if($_POST)
{
if($paypalmode=='sandbox')
{
$paypalmode = '.sandbox';
}
$req = 'cmd=' . urlencode('_notify-validate');
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www'.$paypalmode.'.paypal.com/cgi-bin/webscr');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: www'.$paypalmode.'.sandbox.paypal.com'));
$res = curl_exec($ch);
curl_close($ch);
if (strcmp ($res, "VERIFIED") == 0)
{
$transaction_id = $_POST['txn_id'];
$payerid = $_POST['payer_id'];
$firstname = $_POST['first_name'];
$lastname = $_POST['last_name'];
$payeremail = $_POST['payer_email'];
$paymentdate = $_POST['payment_date'];
$paymentstatus = $_POST['payment_status'];
$mdate= date('Y-m-d h:i:s',strtotime($paymentdate));
$otherstuff = json_encode($_POST);
$conn = mysql_connect($dbhost,$dbusername,$dbpassword);
if (!$conn)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db($dbname, $conn);
// insert in our IPN record table
$query = "INSERT INTO ibn_table
(itransaction_id,ipayerid,iname,iemail,itransaction_date, ipaymentstatus,ieverything_else)
VALUES
('$transaction_id','$payerid','$firstname $lastname','$payeremail','$mdate', '$paymentstatus','$otherstuff')";
if(!mysql_query($query))
{
//mysql error..!
}
mysql_close($conn);
}
}
// PHPmailer ------------------------------------------------------------------------------------
require 'PHPMailerAutoload.php';
$iemail = $_POST['payer_email'];
//Create a new PHPMailer instance
$mail = new PHPMailer;
//Set who the message is to be sent from
$mail->setFrom('from@example.com', 'First Last');
//Set an alternative reply-to address
$mail->addReplyTo('replyto@example.com', 'First Last');
//Set who the message is to be sent to
$mail->addAddress($iemail);
//Set the subject line
$mail->Subject = 'PHPMailer mail() test';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
//$mail->msgHTML(file_get_contents('cont.html'), dirname(__FILE__));
//Replace the plain text body with one created manually
$mail->Body = 'Hello this is a test message';
$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
$mail->addAttachment('images/portfolio/service.jpg');
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
答案 0 :(得分:0)
首先,获取latest PHPMailer。甚至README中的示例也比您在那里的古代代码要好得多。在示例文件夹中查找更复杂的文件夹,包括从MySQL中提取数据以放入您的消息中。