我尝试在我的开发服务器(而不是在localhost)中发送电子邮件,我确实收到了成功消息,但邮件未传递到所需目的地。我已经用两种不同的方式尝试过这种方法,但没有一种方法被送到目的地
代码1
<?php
$msg="";
if(isset($_POST['submit']))
{
$from_add = "name@email.com";
$to_add = "hrisgm@gmail.com";
$subject = "Test Subject";
$message = "Test Message";
$headers = "From: $from_add \r\n";
$headers .= "Reply-To: $from_add \r\n";
$headers .= "Return-Path: $from_add\r\n";
$headers .= "X-Mailer: PHP \r\n";
if(mail($to_add,$subject,$message,$headers))
{
$msg = "Mail sent OK";
}
else
{
$msg = "Error sending email!";
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Test form to email</title>
</head>
<body>
<?php echo $msg ?>
<p>
<form action='<?php echo htmlentities($_SERVER['PHP_SELF']); ?>' method='post'>
<input type='submit' name='submit' value='Submit'>
</form>
</p>
</body>
</html>
代码2
<?php
ini_set('SMTP','https://dev.test.com/');
ini_set('sendmail_from', 'admin@Address.com');
$to = 'tcd@gmal.com';
$subject = 'Example subject';
$body = 'With an example body…';
if(mail($to, $subject , $body)){
echo 'Email has been sent to'.$to;
}
else {
echo "there was an error";
}
?>
任何人都可以帮助我将邮件发送到所需的目的地