我用表单编写了一个非常简单的代码,然后使用 PHPMailer 和 G-suite 获取这些信息并发送电子邮件。我已经在 xampp 上运行了这段代码,一切正常。它正在运行。但是当我把它移到我的主机时没有运行......
PD:我已经阅读过这个错误,它可能是关于文件权限的,但我已经尝试了所有......将所有文件设置为 755,最后我尝试将其设置为 777,但仍然无法正常工作......
我已经联系了托管服务提供商,并说他们可以帮助我解决这个个人问题:/
这是我的 php 代码:
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'phpmailer/src/Exception.php';
require 'phpmailer/src/PHPMailer.php';
require 'phpmailer/src/SMTP.php';
$name="test";
$phone="test";
$email="test";
$mail = new PHPMailer(true);
try {
$password = 'PASSWD';
$mail->SMTPDebug = 2;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = 'email@email.com';
$mail->Password = $password;
$mail->SMTPSecure = 'tsl';
$mail->setFrom('email@email.com', 'Something');
$mail->addAddress('email@email.com');
$mail->addAddress('email@email.com');
$mail->isHTML(true);
$mail->Subject = 'New lead';
$mail->Body = 'Name: '.$name.'<br>Email: '.$email.'<br>Phone: '.$phone;
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
这是我得到的唯一错误:
[客户端 IP] 标头之前的脚本输出结束:send.php
PD:
SMTPSecure 更改为 tls
还是行不通 :(
编辑
这是我得到的错误
117.03.2019 22:04:22 [客户端] AH01215:PHP 解析错误:语法错误,第 3 行出现意外的“使用”(T_USE):
17.03.2019 22:04:34 [client ] AH01215:PHP 警告:使用未定义的常量 \xe2\x80\x98display_errors\xe2\x80\x99 - 假定为 '\xe2\x80\x98display_errors\xe2\x80\x99'(此将在第 2 行的 PHP 的未来版本中抛出错误):
17.03.2019 22:05:14 [客户端] AH01220:等待 CGI 脚本输出的超时
17.03.2019 22:05:14 [客户端] AH00574: ap_content_length_filter: apr_bucket_read() 失败
更新
我将 php 更新到 7.3.2。PHPMailer 在 6.0.7 版本上。我得到的唯一不同的错误是这个......
PHP 警告:在 /第 2 行的 mnt/web401/c2/79/59742679/url:/home/strato/http/power/rid/26/79/59742679/url
更新 2
- php 7.3.2
- PHPMailer 6.0.7
- 套房
- 在 XAMPP 上测试并实际工作
- 在 Strato 上托管
实际代码:
ini_set('display_errors', true);
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'phpmailer2/src/Exception.php';
require 'phpmailer2/src/PHPMailer.php';
require 'phpmailer2/src/SMTP.php';
$name="test";
$phone="test";
$email="test";
$mail = new PHPMailer(true);
try {
$password = 'mypassword';
$mail->SMTPDebug = 3;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = 'myemail';
$mail->Password = $password;
$mail->SMTPSecure = 'tls';
$mail->setFrom('email', 'fromemail');
$mail->addAddress('email');
$mail->addAddress('email');
$mail->isHTML(true);
$mail->Subject = 'New lead';
$mail->Body = 'some text';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
我的文件:
(我正在启动 send2.php 因为它使用的是最新版本的 phpmailer[这个位于 phpmailer2])
当我执行代码时,我在屏幕上看到了这个:
2019-03-20 13:57:54 连接:打开 smtp.gmail.com:587, timeout=300, options=array()
我去我的托管面板,我只是看到这个
20.03.2019 14:55:04 my.website [client 80.38.90.0] AH01215:PHP 警告:使用未定义的常量 \xe2\x80\x98display_errors\xe2\x80\x99 - 假定为 '\xe2\x80\x98display_errors\xe2\ x80\x99'(这将在 PHP 的未来版本中引发错误)在第 2 行的 my.route/send2.php 中:my.route/send2.php
20.03.2019 14:55:44 my.website [client 80.38.90.0] AH01220:超时等待 CGI 脚本 my.route/send2.php 的输出
20.03.2019 14:55:44 my.website [client 80.38.90.0] AH00574: ap_content_length_filter: apr_bucket_read() 失败