我在我的网站上使用像下面这样的行来发送电子邮件后提交的形式。到目前为止,每件事都能如期进行。
现在我想建立我自己的服务器,并希望避免在这个服务器上建立一个电子邮件客户端。谁能告诉我,我需要在这里添加什么来设置一个邮件服务器? 是使用 IP 地址还是需要额外的 PHP 文件来设置?
请注意。 我的邮件只包含文本和一些基本的HTML,没有附件。
我对PHP很陌生,希望能在这里得到一些帮助。
我的 PHP (缩短版)。
// get submitted form data
$postData = $_POST;
// retrieve some post data to include in email
unset($postData);
// prepare email
$to = '[email protected]';
$subject = 'Some text';
$emailBody = '<html><body>Some HTML text</body></html>';
$headers = 'From: Someone <[email protected]>' . PHP_EOL .
'Cc: [email protected] <[email protected]>' . PHP_EOL .
'Reply-To: [email protected] <[email protected]>' . PHP_EOL .
'X-Mailer: PHP/' . phpversion();
// set content-type header for sending HTML email
$headers .= "\r\n". "MIME-Version: 1.0";
$headers .= "\r\n". "Content-type:text/html;charset=UTF-8";
// send email
$mail = mail($to, $subject, $emailBody, $headers);
if($mail) {
header('Location: support.php?status=emailSent');
}
先谢谢你,汤姆
打开你的php.ini文件,寻找"[邮件功能]"。 你可以在这里指定你的SMTP serverportcredentials。
[mail function]
SMTP = smtp.example.com
smtp_port = 25
username = [email protected]
password = yourmailpassord
sendmail_from = [email protected]
在这里,你可以设置它像你的电子邮件客户端在任何机器上你有电子邮件设置。