如何从脚本设置 sendmail 配置?
How to set up the sendmail configration from script?
有没有一种方法可以让我们从 PHP 脚本动态配置 sendmail 设置,而不是手动转到 php.ini 和 sendmail.ini 文件进行更改?
我们可以通过使用允许用户更改值的 HTML 表单来做到这一点吗?
您可以改用诸如 PHPMailer 之类的东西:https://github.com/PHPMailer/PHPMailer
用法示例:
require('./PHPMailer/class.phpmailer.php');
$mail=new PHPMailer();
$mail->CharSet = 'UTF-8';
$body = 'This is the message content';
$mail->IsSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->Username = 'sender@gmail.com';
$mail->Password = '12345';
$mail->SetFrom('sender@gmail.com', $name);
$mail->AddReplyTo('no-reply@mycompany.com','no-reply');
$mail->Subject = 'subject';
$mail->MsgHTML($body);
$mail->AddAddress('abc1@gmail.com', 'title1');
$mail->AddAddress('abc2@gmail.com', 'title2'); /* ... */
$mail->AddAttachment($fileName);
$mail->send();
有没有一种方法可以让我们从 PHP 脚本动态配置 sendmail 设置,而不是手动转到 php.ini 和 sendmail.ini 文件进行更改?
我们可以通过使用允许用户更改值的 HTML 表单来做到这一点吗?
您可以改用诸如 PHPMailer 之类的东西:https://github.com/PHPMailer/PHPMailer
用法示例:
require('./PHPMailer/class.phpmailer.php');
$mail=new PHPMailer();
$mail->CharSet = 'UTF-8';
$body = 'This is the message content';
$mail->IsSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->Username = 'sender@gmail.com';
$mail->Password = '12345';
$mail->SetFrom('sender@gmail.com', $name);
$mail->AddReplyTo('no-reply@mycompany.com','no-reply');
$mail->Subject = 'subject';
$mail->MsgHTML($body);
$mail->AddAddress('abc1@gmail.com', 'title1');
$mail->AddAddress('abc2@gmail.com', 'title2'); /* ... */
$mail->AddAttachment($fileName);
$mail->send();