这是我的代码如下。但是,我无法发送电子邮件。
<!DOCTYPE html>
<html lang="en">
<head>
<title>Sonic Train</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="bootstrap-3.3.6-dist/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Roboto:300,300italic,400" />
<link href="http://fonts.googleapis.com/css?family=PT+Sans+Narrow:400,700" rel='stylesheet' />
<!-- The main CSS file -->
</head>
<body>
<div class="container">
<div class="row" >
<div class="col-sm-12" style="background:url('titleimage.jpg');color:white;"><center><font size="20">Sonic Train</font></center>
<!--<div class="col-sm-12" style="background:url('image1.jpg');color:white; height: 500px;">-->
<center>Train machine learning models at sonic speed...</center></div>
</div>
<div class="row">
<div class="jumbotron" style=" background-color:skyblue;">
<a href='testemail.php?hello=true'>Send an update</a>
<?php
function runMyFunction() {
echo 'I just ran a php function';
$to = 'myemailud@us.edu';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: myemailud@us.edu' . "\r\n" .
'Reply-To: myemailud@us.edu' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
}
if (isset($_GET['hello'])) {
runMyFunction();
}
?>
</div>
</div>
</div>
</body>
</html>
答案 0 :(得分:1)
请尝试以下代码
function runMyFunction() {
echo 'I just ran a php function';
$to = 'myemailud@us.edu';
$subject = 'the subject';
$message = 'hello';
$headers = "Return-Path: myemailud@us.edu\r\n";
$headers .= "From: myemailud@us.edu\r\n";
$headers .= 'MIME-Version: 1.0'."\r\n";
mail($to, $subject, $message, $headers);
}
以上代码在我的网站上正常运行。您是在测试开发环境还是托管服务器上?在开发机器的情况下,我非常怀疑你是否配置了SMTP邮件服务器。 Linux机器有默认的smtp模块。
请提供测试服务器的更多详细信息,并且可以帮助您使用几个命令来验证邮件服务器设置。
您正在检查收件箱中的电子邮件,这是一个邮件客户端,每个人都要求您检查邮件服务器。