我正在通过服务器发送电子邮件,但电子邮件功能无法正常工作。我试图通过echo来调试它的打印直到结束但是如果条件不工作。下面的代码在localhost中正常工作,但在服务器中没有。
<?php
session_start();
?>
<?php
include("connections/db.php");
use phpmailer\phpmailer\phpmailer;
use phpmailer\phpmailer\Exception;
if (isset($_POST['submit'])) {
$date = date("Y-m-d H:i:s");
$Email = $_POST['Email'];
$link =$_POST['link'];
require 'phpmailer/vendor/autoload.php';
include('PHPMailer.php');
include('smtp.php');
$mail = new PHPMailer(true);
$mail->SMTPDebug = 2;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'username@example.com';
$mail->Password = 'password';
$mail->SMTPSecure = 'tls';
$mail->Port = 25;
$mail->setFrom('username@example.com', 'CLOUD ASSESTS');
$mail->addAddress($Email, 'CLoudAssets');
//$mail->addReplyTo('info@example.com', 'Information');
$mail->addCC('cc@example.com');
$mail->addBCC('bcc@example.com');
$mail->Subject = 'Downlink is available here';
$mail->Body = 'Hello this is the download link <b>'.$link.'</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
echo "abc";
if ($mail->send()) {
$_SESSION['isconfirmed'] = 1;
echo "<script>window.location.assign('p3-scenarios.php')</script>";
}
}
?>
发布于 2018-09-30 16:25:11
使用这个代码,希望它会有所帮助:
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';
$mail = new PHPMailer(true);
$name = 'Your Name';
$to = 'to@gmail.com';
$subject = 'Hello World!';
$message = 'This is a test mail!';
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = 'yourmail@gmail.com';
$mail->Password = '*********';
$mail->SMTPSecure = 'tls';
$mail->addReplyTo($to, $name);
$mail->setFrom($to, $name);
$mail->addAddress($to);
$mail->Subject = $subject;
$mail->msgHtml($message);
$mail->send();
只需更改电子邮件和密码即可运行。
希望你在root中包含PHPMailer库,如果是,那么也检查路径。
谢谢!
https://stackoverflow.com/questions/-100002837
复制相似问题