[英]Is there a way to send email using PHPMailer without Composer and in XAMPP
I'm hosting my PHP documents on XAMPP (Apache, not sure why) and I don't want to use composer but still want to use PHPMailer. 我将我的PHP文档托管在XAMPP(Apache,不知道为什么)上,我不想使用composer,但仍然想使用PHPMailer。 No matter where I place classes and index.php it always gives me an error require(): Failed opening required 'PHPMailerAutoload.php' (include_path='C:\\xampp\\php\\PEAR') in C:\\xampp\\htdocs\\PHPMailer-master\\index.php on line 2
无论我将类和index.php放在何处,它总是给我一个错误require():无法在C:\\ xampp \\ htdocs \\中打开所需的'PHPMailerAutoload.php'(include_path ='C:\\ xampp \\ php \\ PEAR')第2行的PHPMailer-master \\ index.php
I've put my index.php in C:\\xampp\\htdocs\\PHPMailer-master (directly downloaded from GitHub) and it still didn't work. 我已经将index.php放在C:\\ xampp \\ htdocs \\ PHPMailer-master(直接从GitHub下载)中,但仍然无法正常工作。
I've used code from this article: How to send an email using PHP? 我使用了本文中的代码: 如何使用PHP发送电子邮件?
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'user@example.com'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
$mail->From = 'from@example.com';
$mail->FromName = 'Mailer';
$mail->addAddress('joe@example.net', 'Joe User'); // Add a recipient
$mail->addAddress('ellen@example.com'); // Name is optional
$mail->addReplyTo('info@example.com', 'Information');
$mail->addCC('cc@example.com');
$mail->addBCC('bcc@example.com');
$mail->WordWrap = 50; // Set word wrap to 50 characters
$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
?>
require_once(APPPATH.'third_party/phpmailer/src/PHPMailer.php');
require_once(APPPATH.'third_party/phpmailer/src/SMTP.php');
$mail = new \PHPMailer(true);
//Server settings
$mail->isSMTP();
//$mail->SMTPDebug = 4; // Enable verbose debug output
$mail->CharSet = "utf-8"; // Set mailer to use SMTP
$mail->Host = 'localhost'; // Specify main and backup SMTP servers
$mail->SMTPAuth = false; // Enable SMTP authentication
$mail->Username = ''; // SMTP username
$mail->Password = ''; // SMTP password
$mail->SMTPSecure = 'ssl';
$mail->Port = 25;//587;
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
//Recipients
$mail->setFrom('noreply@mail.com', 'From name');
$mail->addAddress($mailData['to_email']); // Add a recipient
//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = "Subject";
$mail->Body ="Html contetn";
$mail->send();
return true;
Try to download phpmailer library from trusted source or you can copy the src folder from the phpmailer library downloaded via composer 尝试从受信任的来源下载phpmailer库,或者您可以从通过composer下载的phpmailer库中复制src文件夹
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.