我用表单做了一个非常简单的代码,然后使用PHPMailer和G套件获取这些信息并发送和发送电子邮件。我在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: Parse错误:语法错误,第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‘(这将在未来版本的\xe2\x80\x98display_errors\xe2\x80\x99中引发错误),在第2行: 17.03.2019 22:05:14 client AH01220: Timeout等待CGI脚本的输出 17.03.2019 22:05:14客户端AH00574: ap_content_length_filter: apr_bucket_read()失败
更新
我将php更新为7.3.2。PHPMailer的版本为6.0.7。唯一不同的错误就是这个..。
/home/strato/http/power/rid/26/79/59742679/url警告:在/mnt/url 401/c2/79/59742679/url第2行的/mnt/url 401/c2/79/59742679/url中使用未定义的常量\xe2\x80\x98display_errors\xe2\x80\x99 -假定的'\xe2\x80\x98display_errors\xe2\x80\x99‘(这将在以后的PHP版本中引发错误):
更新2
实际代码:
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,因为它使用的是phpmailerThis的最后一个版本,它位于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警告:使用未定义的常量\xe2\x80\x98display_errors\xe2\x80\x99 -假定的'\xe2\x80\x98display_errors\xe2\x80\x99‘(这将在my.path/send2.php第2行:my.path/send2.php中抛出一个错误) 20.03.2019 14:55:44 my.website客户机80.38.90.0 AH01220:超时等待CGI脚本my.path/send2.php 20.03.2019 14:55:44 my.website客户机80.38.90.0 AH00574: ap_content_length_filter: apr_bucket_read()失败
发布于 2019-03-17 23:17:38
ap_content_length_filter: apr_bucket_read() failed
似乎是这里的相关错误。
这里最有可能的罪魁祸首是到达了Apache (源代码:https://stackoverflow.com/a/38711063/5505001),您应该询问您的web主机是否允许您临时更改Apache,看看这是否真的是问题所在。
发布于 2019-03-18 12:26:48
PHP Parse error: syntax error, unexpected 'use'
这通常意味着您将在一个非常旧的PHPMailer版本上运行一个新版本的PHP。确保您至少使用了PHP5.5,不过现在您只应该在7.3上进行新的开发。
PHP Warning: Use of undefined constant \xe2\x80\x98display_errors\xe2\x80\x99
这是一个复制和粘贴错误-看起来是这样改变了单引号,我使用的卷曲;改变他们回来。
https://stackoverflow.com/questions/55145997
复制相似问题