【问题标题】:failed redirect after mailing send and not send mail发送邮件后重定向失败,不发送邮件
【发布时间】:2014-09-04 06:27:06
【问题描述】:
<?php
include_once('admin/dbcon.php');
if(isset($_POST["submit"])=="Apply Now")
{  
   //$resume='';
   //$photos='';
    $fullname = strip_tags($_POST["fullname"]); 
    $address = strip_tags($_POST["address"]);   
    $state = strip_tags($_POST["state"]);   
    $city = strip_tags($_POST["city"]); 
    $mobile = strip_tags($_POST["mobile"]); 
    $email = strip_tags($_POST["email"]);   
    $username="xxxxxxx";
    $apply_for = strip_tags($_POST["apply_for"]);   
    /*Resume file uploaded*/
        $allowedExts = array("pdf", "doc", "docx"); 
        $extension = end(explode(".", $_FILES["up_resume"]["name"]));
        if ($_FILES["up_resume"]["type"] == "application/pdf" || 
            $_FILES["up_resume"]["type"] == "application/msword" || 
            $_FILES["up_resume"]["type"] == "application/vnd.openxmlformats-officedocument.wordprocessingml.document")
        {     
        $type =substr($_FILES["up_resume"]["name"],strrpos($_FILES["up_resume"]["name"], '.') + 1);
        $resume = "Resume_".time().".".$type;

        move_uploaded_file($_FILES["up_resume"]["tmp_name"], "admin/upload/".$resume); 
        }
        else
        {
        header("Location:apply-now.php?rm=Invalid file, Please upload your updated resume!!");
        }       
    /*Photo uploaded here*/
       $allowedExts1 = array("gif", "jpeg", "jpg", "png");
        $extension1 = end(explode(".", $_FILES["profiel_photos"]["name"]));
        if ($_FILES["profiel_photos"]["type"] == "image/gif" || $_FILES["profiel_photos"]["type"] == "image/jpeg" ||   
            $_FILES["profiel_photos"]["type"] == "image/pjpeg" || $_FILES["profiel_photos"]["type"] == "image/png" || $_FILES["profiel_photos"]["type"] == "image/jpg" )
        {      
        $type1 =substr($_FILES["profiel_photos"]["name"],strrpos($_FILES["profiel_photos"]["name"], '.') + 1);
        $photos = "prf_img_".time().".".$type1;

        move_uploaded_file($_FILES["profiel_photos"]["tmp_name"], "admin/upload/".$photos); 
        }
        else
        {
        header("Location:apply-now.php?pic=Invalid file,Please upload your updated photos!!");
        }
     $status = "INSERT INTO `caretel`.`tb_career` (`FullName`, `Address`, `State`, `City`, `ContactNo`, `Email`, `Resume`, `ProfileImg`, `ApplyFor`) VALUES ('$fullname', '$address', '$state', '$city', '$mobile', '$email', '$resume', '$photos', '$apply_for')";
   if(mysql_query($status))
    {
     require_once('include/class.phpmailer.php');
     $mail = new PHPMailer();
        $mail->IsSMTP(); // 
        $mail->Host       = "smtp.gmail.com"; 
        $mail->SMTPDebug  = 1;                    
        $mail->SMTPAuth   = true;                 
        $mail->Host       = "smtp.gmail.com"; 
        $mail->Port       = 25;                    
        $mail->Username   = "XXXXXX@gmail.com"; 
        $mail->Password   = "XXXXXXX";        
        //$mail->SMTPSecure = "ssl";
        $mail->SMTPSecure = "tls";

       $mail->AddAddress($email,"Guest");
       $mail->SetFrom("cCXXXXXXX@gmail.com","XXXXXXXX");
       $mail->Subject = "New Applicat Applyed for ".$apply_for; 

       $body = 'html';

    $mail->MsgHTML($body);
    $mail->AddAttachment("admin/upload/".$resume);      // attachment
    $mail->AddAttachment("admin/upload/".$photos); // attachment

    if($mail->Send())
    {  
       echo "hi";
        header("Location:apply-now.php?msg=Thank you for Apply. We will be in touch with you very soon!!");

        exit;

    }else{

        header("Location:apply-now.php?msg=We encountered an error sending your mail");

        exit;
        }    
    }
 }else{
 echo "dfsdfsdfsdf ";
 }

?>

邮件未发送且未重定向到 apply-now.php 页面我也使用 ssl 465 和 tls 587 进行端口,并且在我的操作 php 页面上仅重定向邮件发送后未显示任何类型的错误,此代码有什么问题请帮我 谢谢

【问题讨论】:

  • 通过加载 PHPMailer 的自动加载器而不是类来加载 PHPMailer(并确保您使用的是最新版本)。要诊断这一点,请在使用重定向之前整理好您的发送 - 它们往往会阻止您看到调试输出。对于 gmail,您绝对应该在 587 上使用 tls。如果您要使用调试输出,我建议您设置 $mail-&gt;SMTPDebug = 3; 以更全面地了解正在发生的事情。
  • 您可能应该将您的脚本分解为多个部分并独立测试它们(函数或类)。例如使用虚拟数据测试邮件程序。自行测试重定向。测试没有附件的表单提交,最后将所有内容放在一起。我建议使用 Symfony2\HttpFoundation 之类的库来处理请求和重定向,并使用 SwiftMailer 来发送电子邮件。这些库得到了很好的维护和记录。最后使用参数化查询将数据写入您的数据库,您当前的操作方式将使任何人都可以执行 SQL 注入攻击。

标签: php mysql smtp phpmailer


【解决方案1】:

在发送它之前,我们必须修改 PHPMailer 对象以指示该消息应该被解释为 HTML。从技术上讲,消息正文必须设置为多部分/替代。这是通过以下方式完成的:

$mail->IsHTML(true);

更多信息您可以visit here

【讨论】:

  • 不需要:msgHTML() 为您设置。
猜你喜欢
  • 2014-11-18
  • 2016-04-11
  • 2017-02-09
  • 2014-08-09
  • 2015-08-27
  • 2012-05-24
  • 2016-02-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多