[英]How can I use phpmailer without composer
I need to send emails and the mail()
function just does not work for me.我需要发送电子邮件,而
mail()
function 对我不起作用。 The problem is that PHP is not installed on my device.问题是我的设备上没有安装 PHP。 Can I still use it in,
index.php
for example?例如,我还能在
index.php
中使用它吗?
I use 000webhost
我使用
000webhost
Try this code (it works for me):试试这个代码(它适用于我):
<?php
use PHPMailer\PHPMailer\PHPMailer;
require 'PHPMailer.php';
require 'SMTP.php';
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->Username = 'xxx'; // Change here
$mail->Password = 'xxx'; // Change here
$mail->setFrom('xxx', 'Mailer'); // Change here
$mail->addAddress('xxx'); // Change here
$mail->isHTML();
$mail->CharSet = 'utf-8';
$mail->Subject = 'Subject';
$mail->Body = 'Hello world';
echo $mail->Send() ? 'OK!' : 'Something went wrong';
Be sure that:请确保:
PHPMailer.php
and SMTP.php
are in the same folder of the PHP script (I suggest you to put them all in the root of your website, for now); PHPMailer.php
and SMTP.php
are in the same folder of the PHP script (I suggest you to put them all in the root of your website, for now);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.