如何在不更改托管文件的情况下发送邮件(或不在静态托管文件中输入凭据)

how send mail without changing hosting files (or without entering credential in hosting files static)

我搜索了很多如何发送电子邮件,但我发现的是针对特定标准的。2 如下所示;

比如如何从本地主机发送邮件(通过在 sendmail.ini 和其他自定义代码中提供详细信息) 如何从 godaddy 主机发送邮件(使用 PHP Form Mailer)

如果我遵循这个,它会通过更改托管文件变得具体。

虽然有许多脚本(开发的待售站点)允许用户在本地主机或任​​何托管计划上安装这些脚本并输入 smtp 凭据,并且那些脚本能够发送邮件(联系我们表格)而无需更改托管文件.

但我所知道的是在 'sendmail.ini' 文件(id、密码、smtp 服务器)中提供凭据以发送邮件或使用 PHP Form Mailer 进行 godaddy 托管。

但实际上我正在开发网站,我会将其放在 'codycanon' 或其他平台上进行销售,因此在这种情况下,用户可以将其托管在他喜欢的任何主机上。 你能指导我如何在不更改主机文件的情况下发送邮件吗?

使用 PHP MAILER 脚本 https://github.com/PHPMailer/PHPMailer 将它包含在您的项目中并像这样使用它

<?php
require 'PHPMailerAutoload.php';

$mail = new PHPMailer;

//$mail->SMTPDebug = 3;                               // Enable verbose debug output

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'user@example.com';                 // SMTP username
$mail->Password = 'secret';                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;                                    // TCP port to connect to

$mail->setFrom('from@example.com', 'Mailer');
$mail->addAddress('joe@example.net', 'Joe User');     // Add a recipient
$mail->addAddress('ellen@example.com');               // Name is optional
$mail->addReplyTo('info@example.com', 'Information');
$mail->addCC('cc@example.com');
$mail->addBCC('bcc@example.com');

$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}

您的用户所要做的就是使用其托管服务提供商提供的 SMTP 详细信息并将其输入相关变量,您可以更进一步并制作一个交互式 html 页面,您的用户可以在其中输入详细信息并且您的脚本会自动执行编辑配置的过程。

SwiftMailer 也是一个潜在的替代品。