电子邮件发送给PHP后执行脚本

发布于 2025-01-31 07:18:36 字数 2033 浏览 2 评论 0原文

您好,我正在使用SMTP发送电子邮件。电子邮件正在完全发送Schusses,但是电子邮件发送脚本后的脚本不起作用。谁能帮我吗?

电子邮件正在成功发送,但作为回报,脚本没有执行。

还需要发送约2秒钟的电子邮件,但这并不重要,邮件问题是脚本

在此处无法使用的代码

<?php
require 'include/dbconfig.php';


require_once "vendor/autoload.php";


use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

//PHPMailer Object

$mail = new PHPMailer(); //Argument true in constructor enables exceptions
            // SMTP configuration
            $mail->SMTPDebug = 1;   
            $mail->isSMTP();
            $mail->Mailer = "smtp";
            $mail->Host     = "smtp.gmail.com";
            $mail->SMTPAuth = true;
            $mail->Username = "[email protected]";
            $mail->Password = "emailpassword";
            $mail->SMTPSecure = "tls";
            $mail->Port = 587;


            $mail->isHTML(true);
            $mail->setFrom('[email protected]', 'Sabir'); 
          
            $mail->addAddress("[email protected]");
           
           
            $mail->Subject = "Test";
            $mail->Body = "Test Email";
            $email_sent=$mail->send();
                    if(!$email_sent) { ?>
                       <script language="javascript" type="text/javascript">
                     alert('Something went wrong');
                    </script><?php
                } else { ?>
                    <script language="javascript" type="text/javascript">
                     alert('Thank you for the message');
                    </script>
                    <?php
                    }

    ?>

Hello I am sending email with smtp. Email is sending schusses fully but the script after email send script is not working. can anyone help me with this ?

Emails are sending successfully but in return the script is not executing.

Also email take like 2 seconds to send but it does not matter the mail issue is script is not working

Here's code

<?php
require 'include/dbconfig.php';


require_once "vendor/autoload.php";


use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

//PHPMailer Object

$mail = new PHPMailer(); //Argument true in constructor enables exceptions
            // SMTP configuration
            $mail->SMTPDebug = 1;   
            $mail->isSMTP();
            $mail->Mailer = "smtp";
            $mail->Host     = "smtp.gmail.com";
            $mail->SMTPAuth = true;
            $mail->Username = "[email protected]";
            $mail->Password = "emailpassword";
            $mail->SMTPSecure = "tls";
            $mail->Port = 587;


            $mail->isHTML(true);
            $mail->setFrom('[email protected]', 'Sabir'); 
          
            $mail->addAddress("[email protected]");
           
           
            $mail->Subject = "Test";
            $mail->Body = "Test Email";
            $email_sent=$mail->send();
                    if(!$email_sent) { ?>
                       <script language="javascript" type="text/javascript">
                     alert('Something went wrong');
                    </script><?php
                } else { ?>
                    <script language="javascript" type="text/javascript">
                     alert('Thank you for the message');
                    </script>
                    <?php
                    }

    ?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

╰ゝ天使的微笑 2025-02-07 07:18:36

早上好,

您可以减少陈述:

                 $email_sent=$mail->send();
                    if(!$email_sent) { ?>
                   <script language="javascript" type="text/javascript">
                 alert('Something went wrong');
                </script><?php
            } else { ?>
                <script language="javascript" type="text/javascript">
                 alert('Thank you for the message');
                </script>
                <?php
                }

看起来和工作应该这样:

$email_sent = $mail->send();
                if(!$email_sent) {}else {}

您也不需要进行所有这些休息,
只需将JS放在回声中,然后删除它:

language="javascript"

而是去做:

  echo "<script>alert('Something went wrong');</script>";

因此,它看起来就是这样:

     $email_sent = $mail->send();
                if(!$email_sent) { 
    echo "<script>alert('Something went wrong');</script>";
} else {
    echo "<script>alert('Thank you for the message');</script>";
}

编辑

几乎忘记了!

现在我们已经清除了一些代码,
但这不会那样工作。

您将需要与以下方式调整表格:

onclick or onsubmit

或进行Ajax调用:

$('#mailform').on('submit', function(e)
{
    e.preventDefault(); 

        $.ajax({ 
            data:    {data_field: 'value'},
            type:    'post',
            url:     '/script.php',
            success: function(r) {$('#thepoup').removeClass('hidden')},
            error:   function(r) {alert('error'); console.log(r)}
        });
});

Good morning,

you can cut your statements a bit down:

                 $email_sent=$mail->send();
                    if(!$email_sent) { ?>
                   <script language="javascript" type="text/javascript">
                 alert('Something went wrong');
                </script><?php
            } else { ?>
                <script language="javascript" type="text/javascript">
                 alert('Thank you for the message');
                </script>
                <?php
                }

It should look and work like that:

$email_sent = $mail->send();
                if(!$email_sent) {}else {}

Also you don´t need to make all this breaks,
just put your js in a echo and remove that:

language="javascript"

instead go for:

  echo "<script>alert('Something went wrong');</script>";

So it would look like that:

     $email_sent = $mail->send();
                if(!$email_sent) { 
    echo "<script>alert('Something went wrong');</script>";
} else {
    echo "<script>alert('Thank you for the message');</script>";
}

Edit

Nearly forgot!

Now we have cleared the code a bit,
but it won´t work like that.

You will need to adjust your form aswell with:

onclick or onsubmit

Or go for an ajax call:

$('#mailform').on('submit', function(e)
{
    e.preventDefault(); 

        $.ajax({ 
            data:    {data_field: 'value'},
            type:    'post',
            url:     '/script.php',
            success: function(r) {$('#thepoup').removeClass('hidden')},
            error:   function(r) {alert('error'); console.log(r)}
        });
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文