当我单击提交按钮时,它正在加载但没有错误,而且我也没有收到邮件 [英] When I click the submit button it's loading but no error and also i'm not getting mail

查看:50
本文介绍了当我单击提交按钮时,它正在加载但没有错误,而且我也没有收到邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

带有附件的 PHP 电子邮件表单无法通过 PHPMailer 帮助我解决我所缺少的问题.没有表单和 PHP 代码,它可以在 localhost 中工作,但是当我与表单合并时,它完全无法工作..

 Email: '.$email;$file_name = ($_FILES['image']['name']);$file_tmp = ($_FILES['image']['tmp_name']);$file_path = "上传";如果(move_uploaded_file($file_tmp,上传".$file_name)){$mail = new PHPMailer\PHPMailer\PHPMailer();$mail->isSMTP();$mail->Host = Config::SMTP_HOST;$mail->用户名=配置::SMTP_USER;$mail->Password = Config::SMTP_PASS;$mail->Port = Config::SMTP_PORT;$mail->SMTPSecure = 'tls';$mail->SMTPDebug = 2;$mail->SMTPAuth = true;$mail->isHTML(true);$mail->CharSet = 'UTF-8';$mail->setFrom('mail');$mail->addAddress('mail');$mail->Subject = '有问题';$mail->Body = $content;$mail->addAttachment($file_path, $file_name);if($mail->send()){echo '超级';} 别的 {echo 'nothing:' .$mail->ErrorInfo;}}}?><form class="montform" id="reused_form" enctype="multipart/form-data"><div class="col-lg-4 col-md-4 col-sm-12 col-xs-12 bzd-upload-1-1"><div class="col-lg-12 frm-bg"><img src="img/upload-icon.png" class="img-responsive"><p>拖放文件<br/>或在此处上传

<p class="文件"><label for="file_attach"><h6>浏览</h6><input name="image" type="file" id="file" class="feedback-input"></p>

<div class="col-lg-8 col-md-8 col-sm-12 col-xs-12 bzd-form-1-1"><div class="col-lg-6 col-md-6 col-sm-12 col-xs-12 form-group"><label class="form-1-1">名称</label><p class="name"><input name="name" type="text" class="feedback-input" required placeholder="Name" id="name"/></p>

<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12 form-group"><label class="form-1-1">电子邮件</label><p class="email"><input name="email" type="email" required class="feedback-input" id="email" placeholder="Email"/></p>

<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12 form-group"><label class="form-1-1">手机号码</label><p class="name"><input name="phone" type="tel" class="feedback-input" required placeholder="Phone" id="phone"/></p>

<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12 form-group"><label class="form-1-1">材料</label><p class="name"><input name="mat" type="tel" class="feedback-input" required placeholder="Material" id="mat"/></p>

<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12 form-group"><label class="form-1-1">分辨率</label><p class="name"><input name="res" type="tel" class="feedback-input" required placeholder="Resolution" id="res"/></p>

<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12 form-group"><label class="form-1-1">技术</label><p class="name"><input name="tech" type="tel" class="feedback-input" required placeholder="Technology" id="tech"/></p>

<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12 form-group"><label class="form-1-1">城市</label><p class="name"><input name="city" type="text" class="feedback-input" required placeholder="City" id="city"/></p>

<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12 form-group"><label class="form-1-1">Message</label><p class="text"><textarea name="message" class="feedback-input" id="comment" placeholder="Message"></textarea></p>

<div class="提交"><button type="submit" class="button-blue">SUBMIT</button><div class="ease"></div>

</表单>

当我单击提交按钮时,它正在加载...没有显示错误,而且我也没有收到邮件.我也在搜索更多的文章,但仍然没有解决.. 请帮助我..

解决方案

你应该检查你的 error_log 文件,它会告诉你出了什么问题.

实际上 $mail->SMTPDebug = 2; 也会对错误进行故障排除,因此您的电子邮件可能会进入垃圾邮件箱.

这是在我的本地主机上运行的代码:

require_once "vendor/autoload.php";$mail = new PHPMailer\PHPMailer\PHPMailer(true);//或 $mail = new PHPMailer;//开启SMTP调试.$mail->SMTPDebug = 3;//设置$mail->SMTPDebug = 0;在直播网站上.//设置 PHPMailer 使用 SMTP.$mail->isSMTP();//设置SMTP主机名$mail->Host = "smtp.gmail.com";//如果 SMTP 主机需要身份验证才能发送电子邮件,则将此设置为 true$mail->SMTPAuth = true;//提供用户名和密码$mail->用户名 = "useremail@gmail.com";$mail->Password = "密码";//如果SMTP需要TLS加密则设置它//$mail->SMTPSecure = PHPMailer\PHPMailer\PHPMailer::ENCRYPTION_STARTTLS;//设置要连接的TCP端口$mail->端口 = 587;$mail->From = "name@gmail.com";$mail->FromName = "全名";$mail->smtpConnect(大批(ssl" =>大批(verify_peer" =>真的,verify_peer_name" =>真的,allow_self_signed"=>错误的)));//这不需要在本地主机上进行任何服务器设置.$mail->addAddress("Recepient@email.com", "收件人姓名");$mail->isHTML(true);$mail->Subject = "主题文本";$mail->Body = "HTML 格式的邮件正文";$mail->AltBody = "这是邮件内容的纯文本版本";if(!$mail->send()){回声邮件程序错误:".$mail->ErrorInfo;}别的{echo "消息发送成功";}

将凭据更改为您的凭据,看看您的电子邮件是否不会进入垃圾邮件箱.

将您的表单行更改为:<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"class="montform" id="reused_form" enctype="multipart/form-data"> 您的表单中没有 post 方法,它不会将您的值发布到 php 页面.

注意:如果您的 php 代码不在同一页面中!将此 <?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?> 更改为您的 page.php 操作.

将您的上传代码更改为:

$file_name = ($_FILES['image']['name']);$file_tmp = ($_FILES['image']['tmp_name']);$file_path = "上传/";如果(move_uploaded_file($file_tmp,$file_path.$file_name)){

PHP Email form with attachment not working by PHPMailer help me what I'm missing. Without form and PHP code it's working in localhost but when i merge with the form it's totally not working..

 <?php


    require 'vendor/autoload.php';
    require 'classes/config.php';

    if(isset($_POST['submit'])){

    $name = $_POST['name'];
    $email = $_POST['email'];
    $mobile = $_POST['mobile'];
    $mat = $_POST['mat'];
    $res = $_POST['res'];
    $tech = $_POST['tech'];
    $city = $_POST['city'];
    $message = $_POST['message'];
    $content='<br><br>Name: '.$name.'<br>'.'<br>Mobile: '.$mobile .'<br>Material: '.$mat.'<br>Res: '.$res.'<br>tech: '.$tech.'<br>City: '.$city .'<br>Message: '.$message.'<br>Email: '.$email;

    $file_name = ($_FILES['image']['name']);
    $file_tmp = ($_FILES['image']['tmp_name']);
    $file_path = "upload";

    if(move_uploaded_file($file_tmp, "uploads" . $file_name)){

    $mail = new PHPMailer\PHPMailer\PHPMailer();

        $mail->isSMTP();                                          
        $mail->Host       = Config::SMTP_HOST;                    

        $mail->Username   = Config::SMTP_USER;                     
        $mail->Password   = Config::SMTP_PASS;
        $mail->Port       = Config::SMTP_PORT;                               
        $mail->SMTPSecure = 'tls'; 
        $mail->SMTPDebug = 2;  
        $mail->SMTPAuth   = true;   
        $mail->isHTML(true); 
        $mail->CharSet = 'UTF-8';
        $mail->setFrom('mail');
        $mail->addAddress('mail');
        $mail->Subject = 'Got a Enquiry';
        $mail->Body    = $content;
        $mail->addAttachment($file_path, $file_name);

        if($mail->send()){

          echo 'Super';
        } else {

        echo 'nothing:' .$mail->ErrorInfo;

    }
    }
    }

    ?>



<form class="montform" id="reused_form" enctype=&quot;multipart/form-data&quot; >

                        <div class="col-lg-4 col-md-4 col-sm-12 col-xs-12 bzd-upload-1-1">
                            <div class="col-lg-12 frm-bg">
                                <img src="img/upload-icon.png" class="img-responsive">
                                 <p>Drag and Drop Files<br/>
                        or Upload Here</p>
                          <p class="file">

                                    <label for="file_attach">
                               <h6>Browse</h6>
                            </label>
                            <input name="image" type="file" id="file" class="feedback-input">
                        </p>
                            </div>



                        </div>

                         <div class="col-lg-8 col-md-8 col-sm-12 col-xs-12 bzd-form-1-1">


                        <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12 form-group">
                            <label class="form-1-1">Name</label>

                        <p class="name">

                            <input name="name" type="text" class="feedback-input" required placeholder="Name" id="name" />

                        </p>
                             </div>


                       <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12 form-group">  
                           <label class="form-1-1">Email</label>
                        <p class="email">

                            <input name="email" type="email" required class="feedback-input" id="email" placeholder="Email" />

                        </p>
                             </div>

                        <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12 form-group">     
                            <label class="form-1-1">Mobile No</label>
                        <p class="name">

                            <input name="phone" type="tel" class="feedback-input" required placeholder="Phone" id="phone" />

                        </p>
                             </div>

                         <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12 form-group">
                             <label class="form-1-1">Material</label>
                         <p class="name">

                            <input name="mat" type="tel" class="feedback-input" required placeholder="Material" id="mat" />

                        </p>
                             </div>

                         <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12 form-group">  
                             <label class="form-1-1">Resolution</label>
                         <p class="name">

                            <input name="res" type="tel" class="feedback-input" required placeholder="Resolution" id="res" />

                        </p>
                             </div>

                        <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12 form-group">   
                            <label class="form-1-1">Technology</label>
                         <p class="name">

                            <input name="tech" type="tel" class="feedback-input" required placeholder="Technology" id="tech" />

                        </p>
                             </div>

                        <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12 form-group">  
                            <label class="form-1-1">City</label>
                        <p class="name">

                            <input name="city" type="text" class="feedback-input" required placeholder="City" id="city" />

                        </p>
                             </div>

                       <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12 form-group"> 
                           <label class="form-1-1">Message</label>
                        <p class="text">

                            <textarea name="message" class="feedback-input" id="comment" placeholder="Message"></textarea>

                        </p>
                             </div>

                              <div class="submit">
                            <button type="submit" class="button-blue">SUBMIT</button>
                            <div class="ease"></div>
                        </div>

                        </div>    

                    </form>

When I click the submit button it's loading... No error displayed and also i'm not getting mail. I am also search some more articles but still it is not resolved.. kindly help me in this..

解决方案

You should check your error_log file it would show you whats going wrong.

Actualy $mail->SMTPDebug = 2; would create troubleshoots of errors too, so maybe your emails going to spam box.

Here is the code working on my localhost :

require_once "vendor/autoload.php";

$mail = new PHPMailer\PHPMailer\PHPMailer(true);
//Or $mail = new PHPMailer; 
//Enable SMTP debugging. 
$mail->SMTPDebug = 3; 
//Set $mail->SMTPDebug = 0; on live sites.                        
//Set PHPMailer to use SMTP.
$mail->isSMTP();            
//Set SMTP host name                          
$mail->Host = "smtp.gmail.com";
//Set this to true if SMTP host requires authentication to send email
$mail->SMTPAuth = true;                          
//Provide username and password     
$mail->Username = "useremail@gmail.com";                 
$mail->Password = "password";                           
//If SMTP requires TLS encryption then set it
//$mail->SMTPSecure = PHPMailer\PHPMailer\PHPMailer::ENCRYPTION_STARTTLS;                         
//Set TCP port to connect to 
$mail->Port = 587;                                   

$mail->From = "name@gmail.com";
$mail->FromName = "Full Name";

$mail->smtpConnect(
    array(
        "ssl" => array(
            "verify_peer" => true,
            "verify_peer_name" => true,
            "allow_self_signed" => false
        )
    )
);
//This won't require any server settings on your localhost.

$mail->addAddress("Recepient@email.com", "Recepient Name");

$mail->isHTML(true);

$mail->Subject = "Subject Text";
$mail->Body = "<i>Mail body in HTML</i>";
$mail->AltBody = "This is the plain text version of the email content";

if(!$mail->send()) 
{
    echo "Mailer Error: " . $mail->ErrorInfo;
} 
else 
{
    echo "Message has been sent successfully";
}

Change credentials to yours, and see if your emails not going to spam box.

Change your form line to this : <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" class="montform" id="reused_form" enctype="multipart/form-data"> you dont have post method in your form, it doesnt post your values to php page.

NOTE : if your php codes are not in same page! change this <?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?> to your page.php in action.

Change Your upload codes to :

$file_name = ($_FILES['image']['name']);
$file_tmp = ($_FILES['image']['tmp_name']);
$file_path = "upload/";

if(move_uploaded_file($file_tmp, $file_path.$file_name)){

这篇关于当我单击提交按钮时,它正在加载但没有错误,而且我也没有收到邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
PHP最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆