How can I use phpmailer without composer

泄露秘密 提交于 2021-02-11 12:42:55

问题


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?

I use 000webhost


回答1:


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:

  • the files 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);
  • the PHP script (containing the above code) is UTF-8 encoded.


来源:https://stackoverflow.com/questions/65220766/how-can-i-use-phpmailer-without-composer

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!