发送电​​子邮件用PHP / AJAX从HTML表单表单、邮件、AJAX、PHP

2023-09-11 22:30:12 作者:命比纸薄

我要发送的用户已经从一个HTML表单填写了我的电子邮件地址的信息。从我的理解,这不能由仅使用客户端的编码由于如何邮件工作的性质进行,并建议使用PHP(组合使用AJAX)来处理服务器端code。我在这里遵循的指导 ,但我没有收到任何邮件我电子邮件地址。我在我的机器上的本地测试(使用XAMPP)之前,我部署我对我的客户的网络空间(​​Godaddy的)code。我想指出,我从来没有使用过PHP。

JavaScript的:

  VAR数据=这是我的电子邮件;
$阿贾克斯({
    键入:POST,
    网址:email.php
    数据:数据,
    数据类型:文字
});
 

PHP(email.php):

 < PHP
$到=myself@hotmail.com;
$主题=这是我的电子邮件;
$消息= $ _REQUEST;
$ =发送电子邮件($到,$主题,$消息);
如果(!$发送){
    死();
}
?>
 

解决方案

XAMPP没有电子邮件本身发送的东西为默认值。您可以查看下面的链接;

PHP的邮件设置在XAMPP

How我让XAMPP在本地使用PHP的mail()函数,这样我就可以在本地测试我的邮件()脚本,而无需上传到我的服务器?

I want to send the information the user has filled out from an HTML form to my email address. From my understanding, this cannot be done by using only client-side coding due to the nature of how emails work, and suggested to use PHP (combined with AJAX) to handle the server-side code. I followed the guide here but I am not receiving any emails at my email address. I am testing locally on my machine (using XAMPP) before I deploy my code on my client's web space (goDaddy). I want to note that I have never used PHP before.

Javascript:

var data = "This is my email";
$.ajax({
    type: "POST",
    url: "email.php",
    data: data,
    dataType: "text"
});

PHP (email.php):

<?php
$to = "myself@hotmail.com";
$subject = "This is my email";
$message = $_REQUEST;
$send = mail($to, $subject, $message);
if(!$send){    
    die();  
}
?>

解决方案

XAMPP doesn't have an e-mail sending thing by itself as default. You may check the links below;

php mail setup in xampp

How do I enable XAMPP to locally use the php's mail() function so I can test my mail() scripts locally without having to upload to my server?