有没有办法可以从PHP脚本动态配置sendmail设置,而不是手动转到php.ini和sendmail.ini文件进行更改?
我们可以使用允许用户更改值的HTML表单吗?
答案 0 :(得分:0)
您可以使用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();