2

I am a noob to php and databases. But I have an idea to perform mail operations on my own web server (i.e just by database operations), but I really don't have any idea of how to send mail to external websites like gmail. and also I look forward to making my own email-addresses like ex:-myownemail@localhost. I have searched google multiple times but I couldn't find any answer that I could understand. Can anyone tell me in simple words on how to do this?

4

2 回答 2

2

首先你需要有一个虚拟主机,拿一个免费的用于测试目的,它支持邮件功能。然后在您完成主机设置后,请尝试以下操作。

要发送邮件,因为您不在乎它是否会成为垃圾邮件,请使用以下简单的 php 代码:

<?php
$to = "xyz@somedomain.com";
$subject = "This is subject";

$message = "<b>This is HTML message.</b>";
$message .= "<h1>This is headline.</h1>";

$header = "From:abc@somedomain.com \r\n";
$header = "Cc:afgh@somedomain.com \r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-type: text/html\r\n";

$retval = mail ($to,$subject,$message,$header);

if( $retval == true )
{
    echo "Message sent successfully...";
}
else
{
    echo "Message could not be sent...";
}
?>

如果您只想使用 PHP 阅读邮件,PHP 具有与 IMAP、NNTP 和 POP 邮箱对话的本机函数。

于 2015-11-29T06:44:58.140 回答
0

基本上你需要一个mail server和一个程序来访问邮件,它适用于 IMAP(互联网消息访问协议)。

对于邮件服务器和IMAP服务器,我们有很多开源项目。

我发现了这个很棒的教程,它使用了postfixdovecot

http://aurellem.org/free/html/email.html

于 2017-08-18T04:48:12.233 回答