有人可以帮我解决 phpmailer 问题吗?
我已经制作了一封 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在不同的项目中使用 PHPMailer。
我建议你通过SMTP发送邮件,当然PHPMailer支持它:
I use PHPMailer in different projects.
I suggest you to send the mails via SMTP, of course PHPMailer supports it: