我的代码没有产生电子邮件,只是显示一个空白屏幕。我已经将输出与其他电子邮件进行了比较,并且比较标题似乎没有问题。
代码:
function SendEmail($pemail, $pfirst, $plast, $add1,$add2,$pcode) {
$messageplain="Test here is a test ";
$messagehtml = "<p> A test is here </p>";
$myemail = "coconut@gmail.com"; //<-----Put Your email address here. ----->
$test_email="blah@hotmail.co.uk";
$crlf = "\r\n";
echo "<br /><b>Emailing ..." . $pemail. "</b><br />";
$to = $test_email;
//$to = "$first_name $lasyt_name<$pemail";
$email_subject = "With urgent regard your pledge to support Speckled Wood TQ834112";
// Add in our primary content boundary, and mime type specification - for inline attachment image:
$sep = sha1(date('r', time()));
$headers = array
(
// 'Content-Transfer-Encoding: 7bit',
// 'In-Reply-To:'.$sep.'@speckledwood.org.uk',
'Content-Type: multipart/alternative; boundary="-PHP-'.$sep.'"',
// 'To: ' . $to,
'From: Friends of Speckled Wood Management Trust <'.$myemail.'>',
'Reply-To: Friends of Speckled Wood Management Trust <'.$myemail.'>',
'MIME-Version: 1.0',
// 'Date: ' . date('r', $_SERVER['REQUEST_TIME']),
'Message-ID: <' . $_SERVER['REQUEST_TIME'] . md5($_SERVER['REQUEST_TIME']) . '@' . $_SERVER['SERVER_NAME'] . '>',
'X-Mailer: PHP v' . phpversion(),
// 'Return-Path: Friends of Speckled Wood Management Trust <'.$myemail.'>',
// 'X-Originating-IP: ' . $_SERVER['SERVER_ADDR'],
);
$image="../assets/foswmt.jpg";
if(!file_exists($image)) die("ERROR #000001: Fatal Error could not locate email attachment image {$image}");
$attachment = file_get_contents($image);
$encoded = base64_encode($attachment);
$attached = chunk_split($encoded);
$email_body = array
(
'---PHP-'.$sep.'',
'Content-Type: multipart/alternative; boundary="-PHP-'.$sep.'"',
' ',
' ',
'---PHP-'.$sep.'',
'Content Type: text/plain; charset="iso-8859-2"',
// 'Content-Disposition: inline',
'Content-Transfer-Encoding: quoted-printable',
' ',
$messageplain,
' ',
' ',
'---PHP-'.$sep.'',
'Content-Type: text/html; charset="iso-8859-2"',
// 'Content-Disposition: inline',
'Content-Transfer-Encoding: quoted-printable',
' ',
'<html><body>',
'<p><centre><img src="cid:PHP-CID-'.$sep.'" alt="foswmt group" height="200" width="200"></centre></p>',
$messagehtml,
'</body></html>',
'---PHP-'.$sep.'--',
' ',
'---PHP-'.$sep.'',
'Content Type: image/jpeg;',
'Content-Transfer-Encoding: base64',
'Contect-ID: <PHP-CID-'.$sep.'>',
'Content-Disposition: attachment; filename = "logo.jpg"',
$attached,
'---PHP-'.$sep.'--'
);
$email_subject = $pfirst. " ". $plast . " we wish you to make a pledge with urgent regard to Speckled Wood TQ834112";
// $headers .= "Return-Path: http://www.speckledwood.org.uk/donate\r\n";
$sent = mail($to,$email_subject,implode($crlf, $email_body),implode($crlf, $headers));
//echo( "<br /><br />header: <br />" . $headers."body: <br />". $email_body . "<br /><br />");
}
?>
<?php
$count=0;
$countemail=0;
$conlivedata = mysql_pconnect("localhost","user","password");
if (!$conlivedata) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$con = mysql_pconnect("instance41919.db.xeround.com:6326","user","password");
if (!$con) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
mysql_select_db("csv_db", $con)or die("A MySQL error has occurred.Your Query: Error: (" . mysql_errno() . ") " . mysql_error());
$result = mysql_query("SELECT * FROM `tbl_name` WHERE EmailAddr <> ' ' ORDER BY `EmailAddr`", $con) or die("<br/>A MySQL Query error has occurred.Your Query: Error: (" . mysql_errno() . ") " . mysql_error());
$total = (mysql_result($result, 0));
ob_end_flush();
$i=0;
while($row = mysql_fetch_array($result)) {
$Email = $row['EmailAddr'];
$i++;
if ($Email != NULL ){
mysql_select_db("foswood_db", $conlivedata) or die("<br/>A MySQL error has occurred Slecting Database.<br />Your Query: <br/> Error: (" . mysql_errno() . ") " . mysql_error());
$liveresult = mysql_query("SELECT COUNT(*) FROM pledges WHERE EmailAddr = '$Email'", $conlivedata) or die("<br/>A MySQL error has occurred.<br />Your Query: <br /> Error: (" . mysql_errno() . ") " . mysql_error());
if(mysql_result($liveresult, 0) ) {
$count +=1;
} else {
$countemail+= 1;
echo $row['first_name'] . " " . $row['last_name'] . " at : " . $row['street_address']. "," . $row['street_address2']. "-" . $row['street_address']. "." . $row['postcode_address'];
SendEmail($row['EmailAddr'],$row['first_name'],$row['last_name'] ,$row['street_address'],$row['street_address2'],$row['street_address'],$row['postcode_address']);
// Calculate the percentation
$percent = intval(($i/$total) * 100)."%";
// Javascript for updating the progress bar and information
echo '<script language="javascript">
document.getElementById("progress").innerHTML="<div style=\"width:'.$percent.';background-color:#880000;\"> </div>";
document.getElementById("information").innerHTML="'.$i.' row(s) processed.";
</script>';
// This is for the buffer achieve the minimum size in order to flush data
echo str_repeat(' ',1024*64);
// Send output to browser immediately
flush();
}
mysql_select_db("csv_db", $con) or die("<br/>A MySQL error has occurred Slecting Database.<br />Your Query: <br /> Error: (" . mysql_errno() . ") " . mysql_error());
}
echo "<br />";
}
// Tell user that the process is completed
echo '<script language="javascript">document.getElementById("information").innerHTML="Process completed"</script>';
echo "<br/><br/><b/>Totals: " .$countemail." users where emailed . ". $count . " users have pledged.</b/>";
mysql_close($con);
mysql_close($conlivedata);
?>
电子邮件输出:
x-store-info:J++/JTCzmObr++wNraA4Pa4f5Xd6uens1Lp3iK0Ye5aEjPdIeMl+dLztxnwvfAro8TnNo6oBhGA7L/DjzgZOx0ppu40FIoBOCmeUFoon2LHkqEz1HUPWZD8509hWmnOI6C5Vv2MwPthOB2arSXfcxQ==
Authentication-Results: hotmail.com; spf=none (sender IP is 213.146.180.236) smtp.mailfrom=anonymous@plesk1.scl.co.uk; dkim=none header.d=gmail.com; x-hmca=none
X-SID-PRA: blah@gmail.com
X-AUTH-Result: NONE
X-SID-Result: NONE
X-Message-Status: n:n
X-Message-Delivery: Vj0xLjE7dXM9MDtsPTE7YT0xO0Q9MTtHRD0xO1NDTD0w
X-Message-Info: aKlYzGSc+Lm8gD7dwUXYSRNR5LLYBBvh97q7glDSvulIBZntxAmNOdzNstRoIcJdOm3yFA8mQDHaJB3blBVcKgwYxogtqVPN3HhKvyIhWpalwIvoeAaTyHiqoDqbM88C293BzBRm/nMwFkTrFlu4qMmHYqUBkcOD
Received: from plesk1.scl.co.uk ([213.146.180.236]) by BAY0-MC3-F1.Bay0.hotmail.com with Microsoft SMTPSVC(6.0.3790.4900);
Sun, 24 Mar 2013 11:37:33 -0700
Received: (qmail 8872 invoked by uid 33); 24 Mar 2013 18:37:32 +0000
Date: 24 Mar 2013 18:37:32 +0000
To: blah@hotmail.co.uk
Subject: Adam Britton we wish you to make a pledge with urgent regard to Speckled Wood TQ834112
X-PHP-Originating-Script: 10323:EmailUsers2.php
Content-Type: multipart/alternative; boundary="-PHP-12e6e3f21ec76200f42baff8c05e6cbbe0fbe191"
From: Blah <blah@gmail.com>
Reply-To: Blah <blah@gmail.com>
MIME-Version: 1.0
Message-ID: <1364150249e01977f5edd650baa7b5e672a1d5bc96@www.speckledwood.org.uk>
X-Mailer: PHP v5.3.2-1ubuntu4.10
Return-Path: anonymous@plesk1.scl.co.uk
X-OriginalArrivalTime: 24 Mar 2013 18:37:33.0432 (UTC) FILETIME=[A6013F80:01CE28BE]
---PHP-12e6e3f21ec76200f42baff8c05e6cbbe0fbe191
Content-Type: multipart/alternative; boundary="-PHP-12e6e3f21ec76200f42baff8c05e6cbbe0fbe191"
---PHP-12e6e3f21ec76200f42baff8c05e6cbbe0fbe191
Content Type: text/plain; charset="iso-8859-2"
Content-Transfer-Encoding: quoted-printable
Test here is a test
---PHP-12e6e3f21ec76200f42baff8c05e6cbbe0fbe191
Content-Type: text/html; charset="iso-8859-2"
Content-Transfer-Encoding: quoted-printable
<html><body>
<p><centre><img src="cid:PHP-CID-12e6e3f21ec76200f42baff8c05e6cbbe0fbe191" alt="foswmt group" height="200" width="200"></centre></p>
<p> A test is here </p>
</body></html>
---PHP-12e6e3f21ec76200f42baff8c05e6cbbe0fbe191--
---PHP-12e6e3f21ec76200f42baff8c05e6cbbe0fbe191
Content Type: image/jpeg;
Content-Transfer-Encoding: base64
Contect-ID: <PHP-CID-12e6e3f21ec76200f42baff8c05e6cbbe0fbe191>
Content-Disposition: attachment; filename = "logo.jpg"
/9j/4AAQSkZJRgABAgEASABIAAD/7RO4UGhvdG9zaG9wIDMuMAA4QklNA+0AAAAAABAASAAAAAEA
AgBIAAAAAQACOEJJTQQNAAAAAAAEAAAAHjhCSU0EGQAAAAAABAAAAB44QklNA/MAAAAAAAkAAAAA
AAAAAAEAOEJJTQQKAAAAAAABAAA4QklNJxAAAAAAAAoAAQAAAAAAAAACOEJJTQP1AAAAAABIAC9m
ZgABAGxmZgAGAAAAAAABAC9mZgABAKGZmgAGAAAAAAABADIAAAABAFoAAAAGAAAAAAABADUAAAAB
AC0AAAAGAAAAAAABOEJJTQP4AAAAAABwAAD/////////////////////////////A+gAAAAA////
etc...
---PHP-12e6e3f21ec76200f42baff8c05e6cbbe0fbe191--