dongxian1699 2013-05-30 04:09
浏览 19

phpmailer,电子邮件行为之谜

I have been in PHP/email 'hell' - I got close, and can't seem to get to the 'finish line'....

Om using phpmailer to send support requests in a clients site. my process looks like this: FORM -> PROCESS (generate feedback message AND cc message to support) -> mail to sender -> mail to support -> redirect to thank you page.

the issue is two fold: 1) the emails go thru as expected IF i have debuging turned on, but I get the debug AND no redirect 2) if I turn off debug - the email DOES NOT go out AND I get a blank page - with NO redirect

* addendum * The emails just came thru - so it's ONLY a redirect problem... either with or without debug, My meta refresh does not get sent - maybe there's a better way????

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
    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

  • 写回答

1条回答 默认 最新

  • doumei1203 2013-05-30 05:05
    关注

    Your problem may be that some output has already been sent to the browser before the redirect is attempted. You can't normally do a redirect in that situation. If that's the case you may be able to use output buffering as in the following example:

    ob_start();
    //statements that output data to the browser
    print "some text";
    if (!headers_sent()) {
        header('Location: /success.php');
        exit; 
    }
    ob_end_flush();
    

    This can also be turned on by default in the php.ini file with the output buffering directive, in which case you won't need the ob_start() and ob_end_flush() statements. My php.ini file has this:

    output_buffering = 4096
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看