提问人:Aakash Mishra 提问时间:8/17/2023 最后编辑:OlivierAakash Mishra 更新时间:8/17/2023 访问量:31
使用 PDF 发送邮件时的 PHP 邮件程序问题
php mailer problem while sending the mail with pdf
问:
所以当有人发送邮件时,我想用PDF发送邮件。我的代码前段时间正在工作,但它突然停止工作,不知道到底发生了什么导致它这样做。请在此处附加代码,请告诉我到底需要更改什么。
以及为什么它突然停止工作。
<?php
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
require 'vendor/autoload.php';
$mail = new PHPMailer(true);
if (isset($_POST['send'])) {
print_r($_FILES);
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$fname = $_POST["fname"];
$lname = $_POST["lname"];
// $email = $_POST["email"];
$Position = $_POST["Position"];
$LinkedIn = $_POST["LinkedIn"];
$Contact = $_POST["Contact"];
$message = $_POST["message"];
$Subject = "Mail from" . $fname . " " . $lname . ". Position: " . $Position;
$Body = "";
$Body .= "First Name: ";
$Body .= $fname;
$Body .= "\n <br>";
$Body .= "\nLast Name: ";
$Body .= $lname;
$Body .= "\n <br> ";
$Body .= "\nEmail: ";
$Body .= $email;
$Body .= "\n <br>";
$Body .= "\nMessage: ";
$Body .= $message;
$Body .= "\n <br>";
$Body .= "\nPosition: ";
$Body .= $Position;
// $Body .= "\n <br>";
// $Body .= "\nResume: ";
// $Body .= $resume;
$Body .= "\n <br>";
$Body .= "\nPhone no: ";
$Body .= $Contact;
try {
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
$mail->SMTPDebug = SMTP::DEBUG_OFF;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'mail id';
$mail->Password = 'password';
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 587;
$mail->setFrom('[email protected]', 'aaka');
$mail->addAddress($email);
if ($_FILES['attachment']['name'] != null) {
if (move_uploaded_file($_FILES['attachment']['tmp_name'], "uploads/{$_FILES['attachment']['name']}")) {
// $mail->addAttachment("uploads/{$_FILES['attachment']['name']}");
$mail->AddAttachment("uploads/{$_FILES['attachment']['name']}", "{$_FILES['attachment']['name']}");
}
}
$mail->isHTML(true);
$mail->Subject = $Subject;
$mail->Body = $Body;
// $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
// echo '<script>window.location.href="index.php?message_sent";</script>';
// header("Location: sent.html");
echo header("Location: sent.html");
} catch (Exception $e) {
echo header("Location: not sent.html");
}
}
答: 暂无答案
评论