PHP邮件,代码重用失败在第二次包含


php email, code reuse fails on second include

我早些时候发布了一个电子邮件和重新定位问题,但是在尝试了几件事之后,跟踪(在生产中!)哟!)我已经找到了罪魁祸首——但不知道为什么,也不知道从哪里开始。

你会看到,在下面的代码中,我包含了两次'email.php'——因为一个收据给了用户,另一个包含了一些关于用户的元数据,并去了支持…

如果我注释掉第二个包含,我的重定向工作,如果我留下它,它炸弹…通知邮件是有效的,是唯一不同的地方。

我不知所措

PHP FORM PROCESSOR

...
// send two emails
    $_emailTo = $email; // the email of the person requesting
    $_emailBody = $text_body; // the stock response with things filled in
    include ( 'email.php' );
    $_emailTo = $notifyEmail; // the support email address
    $_emailBody = $pretext.$text_body; // pretext added as meta data for support w/ same txt sent to user
//I make it this far in my trace - then nothing 
     include ( 'email.php' );
// relocate
    echo '<META HTTP-EQUIV="Refresh" Content="0; URL=success.php" >';
    exit;

PHP MAILER (email.php)

<?php
    require 'phpmailer/class.phpmailer.php';
//Create a new PHPMailer instance
$mail = new PHPMailer();
//Tell PHPMailer to use SMTP
$mail->IsSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 0;
//Set the hostname of the mail server
$mail->Host = "mail.validmailserver.com";
//Set the SMTP port number - likely to be 25, 465 or 587
$mail->Port = 26;
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication
$mail->Username = "validusername";
//Password to use for SMTP authentication
$mail->Password = "pass1234";
//Set who the message is to be sent from
$mail->SetFrom('me@validmailserver.com', 'no-reply @ this domain');
//Set an alternative reply-to address
//$mail->AddReplyTo('no-reply@validmailserver.com','Support');
//Set who the message is to be sent to
$mail->AddAddress( $_emailTo );
$mail->Subject = $_emailSubject;
$mail->MsgHTML( $_emailBody );
$_emailError = false;
//Send the message, check for errors
if( !$mail -> Send() ) {
    $_emailError = true;
    echo "Mailer Error: " . $mail->ErrorInfo;
} 
?>

help - please

引起问题的是email.php中的require。如果你想做最少的改变,并使其工作,将其更改为require_once。这将确保"phpmailer/class.phpmailer.php"只被加载一次,因此该类将只被定义一次。

从email.php中取出require()行并将其放入调用文件