如何在没有作曲家的情况下使用 phpmailer [英] How can I use phpmailer without composer
本文介绍了如何在没有作曲家的情况下使用 phpmailer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要发送电子邮件,而 mail()
函数对我不起作用.问题是我的设备上没有安装 PHP.我还可以在 index.php
中使用它吗?
I need to send emails and the mail()
function just does not work for me.
The problem is that PHP is not installed on my device. Can I still use it in, index.php
for example?
我使用 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';
请确保:
PHPMailer.php
和SMTP.php
文件在 PHP 脚本的同一个文件夹中(我建议你把它们都放在你网站的根目录下,暂时);- PHP 脚本(包含上述代码)采用 UTF-8 编码.
- the files
PHPMailer.php
andSMTP.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); - the PHP script (containing the above code) is UTF-8 encoded.
这篇关于如何在没有作曲家的情况下使用 phpmailer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文