我正在研究一个小型项目,该项目使用phpmailer和smtp4dev作为邮件服务器以PHP发送电子邮件,但似乎没有任何效果。 我不断收到此错误消息
连接失败。错误2:加载cafile流失败: C:\ xampp \ apache \ bin \ curl-ca-bundle.crt' [C:\ xampp \ htdocs \ phpmailer \ src \ SMTP.php第405行]`
我曾尝试按照其他人的建议更改证书和路径,尤其是cacert.pem
,但遇到相同的错误。
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'phpmailer/src/Exception.php';
require 'phpmailer/src/PHPMailer.php';
require 'phpmailer/src/SMTP.php';
if($_POST){
// include database connection
include 'database.php';
// validate input data
$name = $_POST['first_name'];
$company = $_POST['last_name'];
$email = $_POST['email'];
$subject = $_POST['phone'];
// check length of data
if ( strlen($name) == 0 || strlen($company) == 0 || strlen($email) == 0 || strlen($subject) == 0 ){
echo '<div class="alert alert-success miemi alert-dismissible fade show" role="alert">
Please provide valid credentials.
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>';
} else {
// credentials are valid
// validate email and phone
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
// throw error email is inavlid
echo '<div class="alert alert-warning miemi alert-dismissible fade show" role="alert">
Please Provide a valid email address
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>';
} else {
// email is valid
// execute sql
try{
// Here we create a variable that calls the prepare() method of the database object
// The SQL query you want to run is entered as the parameter, and placeholders are written like this :placeholder_name
$stmt = $con->prepare("INSERT INTO Revenue (first_name, last_name, email, phone) VALUES (:first_name, :last_name, :email, :phone)");
// Now we tell the script which variable each placeholder actually refers to using the bindParam() method
// First parameter is the placeholder in the statement above - the second parameter is a variable that it should refer to
$stmt->bindParam(':first_name', $name);
$stmt->bindParam(':last_name', $company);
$stmt->bindParam(':email', $email);
$stmt->bindParam(':phone', $subject);
$name = $_POST['first_name'];
$company = $_POST['last_name'];
$email = $_POST['email'];
$subject = $_POST['phone'];
// try to execute
if($stmt->execute()){
// check data inserted correctly
if ($stmt->rowCount() > 0)
{
echo "
<div class='alert miemi alert-success'>
<span class='closebtn'>×</span>
We have sent the file to your email.
</div>
";
// sending email
$mail = new PHPMailer;
//Enable SMTP debugging.
$mail->SMTPDebug = 3;
//Set PHPMailer to use SMTP.
$mail->isSMTP();
//Set SMTP host name
$mail->Host = "******";
//Set this to true if SMTP host requires authentication to send email
$mail->SMTPAuth = true;
//Provide username and password
$mail->Username = "****";
$mail->Password = "*****";
//If SMTP requires TLS encryption then set it
$mail->SMTPSecure = 'tls';
//Set TCP port to connect to
$mail->Port = 587;
$mail->From = "****";
$mail->FromName = "***";
$mail->addAddress("***", "***");
//Provide file path and name of the attachments
$mail->addAttachment("Agile-Team-Charter.docx", "Agile-Team-Charter.docx");
$mail->addAttachment("Agile-Team-Charter.docx"); //Filename is optional
$mail->isHTML(true);
$mail->Subject = "Test email";
$mail->Body = "<i>Mail body in HTML</i>";
$mail->AltBody = "This is the plain text version of the email content";
if(!$mail->send())
{
echo '<div class="alert alert-danger alert-dismissible fade show" role="alert">
We are unable to send you email.Pleas contact our support desk for more information.
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>';
}else
{
// error box
echo '<div class="alert alert-success alert-dismissible fade show" role="alert">
Please check your email. We have sent you the course outline in your email address.
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>';
}
// sending email
} else {
// dtat was not inserted correctly
echo '<div class="alert alert-danger miemi alert-dismissible fade show" role="alert">
We could not register your credentials . Please try again later.
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>';
}
// print_r($statement->errorInfo());
}else{
// dtat was not inserted correctly
echo '<div class="alert alert-danger alert-dismissible fade show" role="alert">
We are experiencing difficulties registering your credentials . Please try again later.
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>';
}
}// show error
catch(Exception $exception){
die('ERROR: ' . $exception->getMessage());
}
}
}
}
?>
有人建议我如何在本地主机和在线cpanel上进行此类配置