我正在尝试发送电子邮件时发送电子邮件'按下按钮,但以下代码不会向我的电子邮件发送任何内容:
<!DOCTYPE html>
<html>
<form action="email.php" method="post">
<input value="Send Email" name="email" type="submit">
</form>
<?php
if (isset($_POST['email'])) {
$msg = 'hello';
mail('example@gmail.com', 'Sample', $msg);
}
?>
</html>
关于如何使其发挥作用的任何想法?
答案 0 :(得分:1)
使用以下PHP代码发送电子邮件
<?php
$to = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
邮件功能在本地服务器中不起作用。您需要在本地服务器上配置SMTP。看看这篇类似的帖子,
答案 1 :(得分:0)
试试这个
<?php
$to = "someemail.com"
$subject = "This is subject";
$message = "<b>This is message.</b>";
$message .= "<h1>This is headline.</h1>";
$header = "From:abc@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...";
}
?>