有人可以帮我解决 phpmailer 问题吗?

发布于 2024-12-10 17:16:09 字数 1916 浏览 0 评论 0原文

我已经制作了一封 HTML 电子邮件,到目前为止一切正常。我打算用 PHP 发送它(使用 mail(); 函数)。然而,当我这样做时,邮件没有到达hotmail和gmail帐户。我用谷歌搜索了一下,人们建议使用 PHPmailer。

我下载了 PHPmailer 并将其安装在我的服务器上。到目前为止,一切都很好。但现在我有以下代码:

<?php
set_include_path('.:c:\domains\mydomain\wwwroot\phpmailer\phpmailer.inc.php');
set_include_path('.:c:\domains\mydomain\wwwroot\phpmailer\smtp.inc.php');

require("phpmailer.inc.php");


$mail = new PHPMailer();

$mail->IsHTML(true);
$mail->From     = "[email protected]";
$mail->AddAddress("[email protected]");

$mail->Subject  = "An HTML Message";
$mail->Body     = "Hello, <b>my friend</b>! \n\n This message uses HTML entities!";

if($mail->Send()) {
  echo 'Message is sent';

} else {
  echo 'Message was not sent..';
 echo 'Mailer error: ' . $mail->ErrorInfo;
}
?>

我遇到了几个问题:

  • 输出告诉我电子邮件未发送,但它确实发送了。
  • 我有两个主题
  • 如果我添加更多 html(如表格),它仍然会被 hotmail(也可能是 gmail)拒绝。

另外,我看到有一个 SMTP 功能。如何使用这个功能呢?我需要写下我自己的 SMTP 吗?

如果有人能帮助我,我会很高兴!

编辑:

class SMTP {
    var $SMTP_PORT = 25; # the default SMTP PORT
    var $CRLF = "\r\n";  # CRLF pair

    var $smtp_conn;      # the socket to the server
    var $error;          # error if any on the last call
    var $helo_rply;      # the reply the server sent to us for HELO

    var $do_debug;       # the level of debug to perform

    /*
     * SMTP()
     *
     * Initialize the class so that the data is in a known state.
     */
    function SMTP() {
        $this->smtp_conn = 0;
        $this->error = null;
        $this->helo_rply = null;

        $this->do_debug = 0;
    }

I've made a HTML email and everything has worked so far. I was planning to send it with PHP (using the mail(); function). However, when I did this, the mail did not arrive at hotmail and gmail accounts. I googled around a bit and people suggested to use PHPmailer.

I downloaded PHPmailer and installed it on my server. So far, so good. But now I have the following code:

<?php
set_include_path('.:c:\domains\mydomain\wwwroot\phpmailer\phpmailer.inc.php');
set_include_path('.:c:\domains\mydomain\wwwroot\phpmailer\smtp.inc.php');

require("phpmailer.inc.php");


$mail = new PHPMailer();

$mail->IsHTML(true);
$mail->From     = "[email protected]";
$mail->AddAddress("[email protected]");

$mail->Subject  = "An HTML Message";
$mail->Body     = "Hello, <b>my friend</b>! \n\n This message uses HTML entities!";

if($mail->Send()) {
  echo 'Message is sent';

} else {
  echo 'Message was not sent..';
 echo 'Mailer error: ' . $mail->ErrorInfo;
}
?>

I got several problems:

  • The output tells me the email is not sent, but it is.
  • I get two subjects
  • If I add more html (like a table), it still gets rejected by hotmail (and probably gmail too).

Also, I saw there's a SMTP function. How to use this function? Do I need to write down my own SMTP?

Would be very happy if someone could help me out!

edit:

class SMTP {
    var $SMTP_PORT = 25; # the default SMTP PORT
    var $CRLF = "\r\n";  # CRLF pair

    var $smtp_conn;      # the socket to the server
    var $error;          # error if any on the last call
    var $helo_rply;      # the reply the server sent to us for HELO

    var $do_debug;       # the level of debug to perform

    /*
     * SMTP()
     *
     * Initialize the class so that the data is in a known state.
     */
    function SMTP() {
        $this->smtp_conn = 0;
        $this->error = null;
        $this->helo_rply = null;

        $this->do_debug = 0;
    }

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

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

发布评论

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

评论(1

自此以后,行同陌路 2024-12-17 17:16:09

我在不同的项目中使用 PHPMailer。

我建议你通过SMTP发送邮件,当然PHPMailer支持它:

$mail = new PHPMailer();
$mail->IsSMTP();     // send via SMTP
$mail->Host = "smtp.gmail.com" //(or the smtp server you use)
$mail->Port = "465" //(gmail uses secure smtp so that runs on port 465)
$mail->SMTPAuth  = "true"   //we need to autenticate to the server
$mail->SMTPSecure = "ssl"  //we use ssl to protected the flow of info
$mail->Username = "[email protected]" //account 
$mail->Password = "password" //password


//build the message
 $mail->IsHTML(true);
$mail->From     = "[email protected]";
$mail->AddAddress("[email protected]"); //who receives the mail
$mail->Subject  = "An HTML Message";
$mail->Body     = "Hello, <b>my friend</b>! \n\n This message uses HTML entities!";

if($mail->Send()) {
  echo 'Message is sent';

} 
else {
  echo 'Message was not sent..';
 echo 'Mailer error: ' . $mail->ErrorInfo;
}

I use PHPMailer in different projects.

I suggest you to send the mails via SMTP, of course PHPMailer supports it:

$mail = new PHPMailer();
$mail->IsSMTP();     // send via SMTP
$mail->Host = "smtp.gmail.com" //(or the smtp server you use)
$mail->Port = "465" //(gmail uses secure smtp so that runs on port 465)
$mail->SMTPAuth  = "true"   //we need to autenticate to the server
$mail->SMTPSecure = "ssl"  //we use ssl to protected the flow of info
$mail->Username = "[email protected]" //account 
$mail->Password = "password" //password


//build the message
 $mail->IsHTML(true);
$mail->From     = "[email protected]";
$mail->AddAddress("[email protected]"); //who receives the mail
$mail->Subject  = "An HTML Message";
$mail->Body     = "Hello, <b>my friend</b>! \n\n This message uses HTML entities!";

if($mail->Send()) {
  echo 'Message is sent';

} 
else {
  echo 'Message was not sent..';
 echo 'Mailer error: ' . $mail->ErrorInfo;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文