下面是php和html,但它不会将信息发送到我的电子邮箱。我觉得它与我在php.ini文件中的设置有关。我也会包括我的编辑。如果您有任何想法,将不胜感激!
在php.ini中修改了以下内容:
SMTP = outlook.office365.com
sendmail_from = email@mydomain.com
HTML:
<form method="POST" action="email-sender.php" id="contact-form-with-recaptcha" class="margin-clear" role="form">
<div class="form-group has-feedback">
<label for="name">Name*</label>
<input type="text" class="form-control" id="name" name="name" placeholder="">
<i class="fa fa-user form-control-feedback"></i>
</div>
<div class="form-group has-feedback">
<label for="email">Email*</label>
<input type="email" class="form-control" id="email" name="email" placeholder="">
<i class="fa fa-envelope form-control-feedback"></i>
</div>
<div class="form-group has-feedback">
<label for="subject">Subject*</label>
<input type="text" class="form-control" id="subject" name="subject" placeholder="">
<i class="fa fa-navicon form-control-feedback"></i>
</div>
<div class="form-group has-feedback">
<label for="message">Message*</label>
<textarea class="form-control" rows="6" id="message" name="message" placeholder=""></textarea>
<i class="fa fa-pencil form-control-feedback"></i>
</div>
<input type="submit" value="Submit" class="submit-button btn btn-default">
</form>
PHP:
<?php
session_cache_limiter('nocache');
header('Expires: ' . gmdate('r', 0));
header('Content-type: application/json');
$Recipient = 'email@mydomain.coom'; // <-- I had put my email here
if($Recipient) {
$Name = filter_var($_POST['name'], FILTER_SANITIZE_STRING);
$Email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
$Subject = filter_var($_POST['subject'], FILTER_SANITIZE_STRING);
$Message = filter_var($_POST['message'], FILTER_SANITIZE_STRING);
$Email_body = "";
$Email_body .= "From: " . $Name . "\n" .
"Email: " . $Email . "\n" .
"Subject: " . $Subject . "\n" .
"Message: " . $Message . "\n" .
$Email_headers = "";
$Email_headers .= 'From: ' . $Name . ' <' . $Email . '>' . "\r\n".
"Reply-To: " . $Email . "\r\n";
$sent = mail($Recipient, $Subject, $Email_body, $Email_headers);
if ($sent){
$emailResult = array ('sent'=>'yes');
} else{
$emailResult = array ('sent'=>'no');
}
echo json_encode($emailResult);
} else {
$emailResult = array ('sent'=>'no');
echo json_encode($emailResult);
}
?>
我认为这会奏效,但我可能犯了一个错误。如果您有任何注意事项,请不要错过!
答案 0 :(得分:0)
您可以使用gmail通过localhost发送电子邮件。使用您的电子邮件ID和密码为sendmail设置php.ini。
smtp_server=smtp.gmail.com
smtp_port=25
error_logfile=error.log
debug_logfile=debug.log
auth_username=myemail@gmail.com
auth_password=gmailpassword
注意:执行更改后,请重新启动服务器。 force_sender=myemail@gmail.com