简体   繁体   English

如何在没有作曲家的情况下使用 phpmailer

[英]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:请确保:

  • 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 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. PHP 脚本(包含上述代码)是 UTF-8 编码的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM