0

当我尝试发送带有从数据库中获取数据的 php 文件附件的多封邮件时,在成功发送邮件后,当它到达 gmail 时,我在邀请.php 文件中得到空白链接,这意味着在发送邮件 php 文件后没有获取来自数据库的数据,因此它没有显示任何链接,但所有其他内容都显示良好,并且在 localhost php 链接中显示正确

这是我的代码

索引.php

<?php 
if(!empty($_POST['invite'])) {
foreach($_POST['invite'] as $check) {
    }
$import_emails =  implode($_POST['invite'], ',');
$imp_eml = explode(',', $import_emails); 

foreach ($imp_eml as $addr)
{
$mail->AddBCC($addr);
}  
$mail = new PHPMailer();
$body = file_get_contents('invite.php');
$body = eregi_replace("[\]",'',$body);
$mail->MsgHTML($body);
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->From = 'info@myweb.com';
$mail->FromName = 'Someone';
$mail->Host = '********';
$mail->SMTPAuth = true; 
$mail->Username = '*******';
$mail->Password = '*******';

if($mail->Send())
{
 echo "success";
} else {
 echo "failure";
} 
}
?>

邀请.php

<?php
include("connect.php")
$customerid = $_REQUEST['customerId']; //comming from another page

$query = mysql_query("select * from  table where customerId = '$customerid'");
 while($fetch=mysql_fetch_array($query)) {
 $prjid = $fetch['projectId'];
 }
?>
Vote for my projects <?php echo '<a href="http://www.mywebsite.com/project-details/'.$c_id.'/'.$p_id.'/">here</a>'; ?>.<br/>
<a href="http://www.mywebsite.com/project-details/<?php echo $c_id.'/'.$p_id.'/'; ?>"><?php echo 'http://www.mywebsite.com/project-details/'.$c_id.'/'.$p_id.'/'; ?></a>
?>

你有什么想法吗?

4

2 回答 2

3

file_get_contents()只会得到文件的内容(惊喜:))。要执行它,您必须使用includeorrequire并使用ob_*().

我认为创建将链接作为字符串返回以避免使用输出缓冲的函数会更好。

关于输出缓冲你可以在这里阅读:http: //php.net/manual/en/book.outcontrol.php

于 2013-10-08T15:29:13.903 回答
0

我找到了一种解决方案。尝试这个

<?php
$con = mysqli_connect('localhost', 'username', 'password', 'databasename');
if (!$con)
{
    die("error" . mysqli_connect_error());
}

error_reporting(E_ERROR);
$filename = "email_data";
$sql = mysqli_query($con, "SELECT * FROM email_data order by id asc limit 0,100");
$row = mysqli_fetch_assoc($sql);
$filename2='datas/'.$filename.'.csv';
$fp = fopen($filename2, "w");
$seperator = "";
$comma = "";
foreach ($row as $name => $value){$seperator .= $comma . '' . str_replace('', '""', $name);$comma = ",";}
$seperator .= "\n";
$seperator;
fputs($fp, $seperator);
mysqli_data_seek($sql, 0);
while ($row = mysqli_fetch_assoc($sql))
{
    $seperator = "";
    $comma = "";
    foreach ($row as $name => $value){$seperator .= $comma . '' . str_replace('', '""', $value);$comma = ",";}
    $seperator .= "\n";
    fputs($fp, $seperator);
}

fclose($fp);

$my_file = $filename2;
$path = "datas/";
$from_name = "solomon";
$from_mail = "pss@gmail.com";
$mailto = "pssworkcse@gmail.com";
$subject = "This is a mail with attachment.";
$message = "Hi,\r\n do you got attachment?\r\n\r\Solomon";
$replyto = "pssworkcse@gmail.com";
$file = $my_file;
$file_size = filesize($file);
$handle = fopen($file, "r");
$content = fread($handle, $file_size);
fclose($handle);
$content = chunk_split(base64_encode($content));
$uid = md5(uniqid(time()));
$name = basename($file);
$header = "From: " . $from_name . " <" . $from_mail . ">\r\n";
$header .= "Reply-To: " . $replyto . "\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/mixed; boundary=\"" . $uid . "\"\r\n\r\n";
$header .= "This is a multi-part message in MIME format.\r\n";
$header .= "--" . $uid . "\r\n";
$header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
$header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$header .= $message . "\r\n\r\n";
$header .= "--" . $uid . "\r\n";
$header .= "Content-Type: application/octet-stream; name=\"" . $filename2 . "\"\r\n"; 
$header .= "Content-Transfer-Encoding: base64\r\n";
$header .= "Content-Disposition: attachment; filename=\"" . $filename2 . "\"\r\n\r\n";
$header .= $content . "\r\n\r\n";
$header .= "--" . $uid . "--";
mail($mailto, $subject, "", $header)

?>
于 2019-12-27T08:09:56.020 回答