简体   繁体   English

PHPMailer 无法在网页中工作

[英]PHPMailer not working in web page

I'm trying to send an email with PHPMailer, but it's not working for me so far.我正在尝试使用 PHPMailer 发送电子邮件,但到目前为止它对我不起作用。

On my FTP I've put 2 files, the class.phpmailer.php and sendEMail.php (this file is created by me), with this content:在我的 FTP 上,我放了 2 个文件, class.phpmailer.phpsendEMail.php (这个文件是我创建的),内容如下:

<?php
require_once('/var/www/vhosts/MYWEBPAGE/httpdocs/class.phpmailer.php');

$mail = new PHPMailer();
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->Host = "mail.dom.com"; 
$mail->Username = "smpt@mail.com"; 
$mail->Password = "passwd"; 
$mail->Port = 25; 

$mail->setFrom("my@mail.com", "me", 0);

$mail->addAddress("to@mail.com"); 

$mail->Subject = "test"; 
$body = "Hello World!";
$mail->Body = $body; 

if(!$mail->send()) {
echo ("Invoice could not be send. Mailer Error: " . $mail->ErrorInfo);
} else {
echo "Invoice sent!";
}

?>

I'm missing something?我错过了什么? When I execute this file, it shows me nothing, i mean before the if(!$mail->send()) {... It shows me every echo, but after that line, it shows me nothing.当我执行这个文件时,它什么也没显示,我的意思是在 if(!$mail->send()) {... 它显示了每个回声,但在那行之后,它什么也没显示。

It's because you've not read the readme that tells you what files you need, nor based your code on the examples provided.这是因为您没有阅读说明您需要哪些文件的自述文件,也没有根据提供的示例编写代码。 You've not loaded the SMTP class, nor the autoloader that will load it for you, so as soon as you try to send, it will fail to find the SMTP class.您没有加载 SMTP 类,也没有为您加载它的自动加载器,因此一旦您尝试发送,它就会无法找到 SMTP 类。 This will be logged in your web server logs like any other PHP fatal error.这将像任何其他 PHP 致命错误一样记录在您的 Web 服务器日志中。

Instead of this:取而代之的是:

require_once('/var/www/vhosts/MYWEBPAGE/httpdocs/class.phpmailer.php');

do this:做这个:

require '/var/www/vhosts/MYWEBPAGE/httpdocs/PHPMailerAutoload.php';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM