我正在尝试使用php函数mail()
发送和发送电子邮件。我明白,如果函数返回true,则不一定意味着邮件已被发送。
我安装了phpmail
软件包和libphp-phpmailer
软件包,但仍然没有...
这是代码:
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
Name: <input type="text" name="name"/>
Mail: <input type="text" name="mail"/>
<input type="submit" value="Send"/>
</form>
<?php
ini_set('display_errors', 1);
error_reporting(~0);
if (isset($_POST["mail"]) && isset($_POST["name"])) {
$to_mail = $_POST["mail"];
$to_name = ucfirst($_POST["name"]);
$subject = "Sent using php";
$message = "Hi " . $to_name . ", we're glad you could join us. Hope you like our page and that you're studing a lot! Good luck with whatever you're doing! :D";
$from = "email@gmail.com";
if(mail($to_mail, $subject, $message, $from)) {
echo "E-Mail Sent to " . $to_mail;
} else {
echo "Could not send E-Mail";
}
}
?>