PHPMailer 不会发送带有不在上传文件夹中的附件的电子邮件(仅在生产中)
PHPMailer won't send an email with attachment which is not already in the uploads folder(Only in production)
我正在我的网站上制作联系我们表格,我使用 PHPMailer 处理将表格发送到我的电子邮件,在我的本地主机和我使用的免费在线主机 (Heroku) 上一切正常用于测试网站。公司发布网站时出现问题,当我们附加上传文件夹中不存在的文件(或与上传文件夹中的文件名称不同)时,表单不会提交。
有没有人遇到过这个问题,是代码问题还是服务器问题还是什么?
这是我的代码:
$path = 'upload/' . $_FILES["personalCV"]["name"];
move_uploaded_file($_FILES["personalCV"]["tmp_name"], $path);
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
$mail = new PHPMailer(true);
try {
//Server settings
// $mail->SMTPDebug = 2; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username =// <SMTP username>
$mail->Password =// <SMTP password>
$mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465;
//Recipients
$mail->setFrom(<email>, <AS Website>);
$mail->addAddress(<address>, <name>);
$mail->addAddress(<address>, <name>); // Add a recipient
// Attachments
$mail->AddAttachment($path);
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'New Job Application From The AS Website ( '.$position.' )';
$msg = '<p> Name : '.$firstName.' '.$lastName.'</p>
<p>Email Address: '.$email.'
</p> <p>Phone Number: '.$phoneNum.'</p>
<p>Position Appling For: '.$position.'</p>
<p> Message: '.$message.'</p>';
$mail->Body = $msg;
$mail->send();
$successMsg = '<div class="alert alert-success" role="alert">
Message successfully sent
</div>';
} catch (Exception $e) {
$failMsg = '<div class="alert alert-danger" role="alert">
Message not successfully sent, please try again
</div>';
}
}
问题已解决,是服务器配置的问题。
我正在我的网站上制作联系我们表格,我使用 PHPMailer 处理将表格发送到我的电子邮件,在我的本地主机和我使用的免费在线主机 (Heroku) 上一切正常用于测试网站。公司发布网站时出现问题,当我们附加上传文件夹中不存在的文件(或与上传文件夹中的文件名称不同)时,表单不会提交。
有没有人遇到过这个问题,是代码问题还是服务器问题还是什么?
这是我的代码:
$path = 'upload/' . $_FILES["personalCV"]["name"];
move_uploaded_file($_FILES["personalCV"]["tmp_name"], $path);
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
$mail = new PHPMailer(true);
try {
//Server settings
// $mail->SMTPDebug = 2; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username =// <SMTP username>
$mail->Password =// <SMTP password>
$mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465;
//Recipients
$mail->setFrom(<email>, <AS Website>);
$mail->addAddress(<address>, <name>);
$mail->addAddress(<address>, <name>); // Add a recipient
// Attachments
$mail->AddAttachment($path);
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'New Job Application From The AS Website ( '.$position.' )';
$msg = '<p> Name : '.$firstName.' '.$lastName.'</p>
<p>Email Address: '.$email.'
</p> <p>Phone Number: '.$phoneNum.'</p>
<p>Position Appling For: '.$position.'</p>
<p> Message: '.$message.'</p>';
$mail->Body = $msg;
$mail->send();
$successMsg = '<div class="alert alert-success" role="alert">
Message successfully sent
</div>';
} catch (Exception $e) {
$failMsg = '<div class="alert alert-danger" role="alert">
Message not successfully sent, please try again
</div>';
}
}
问题已解决,是服务器配置的问题。