2015-04-25 215 views
-2

我没有使用任何PHP,并想使我的html文件的形式发送一封电子邮件,而无需使用的mailto:通过PHP发送电子邮件?

我在网上找了如何做一些这方面的教程,和最好的我可以做我自己是这个。

<form method="POST" action="contact.php"> 
       <input type="text" name="FirstName" placeholder="First Name" size="24px"/> <input type="text" name="LastName" placeholder="Last Name" size="24px"/><br> 
       <input type="tel" name="Phone" placeholder="Address" size="53px"/><br> 
       <input type="text" name="Address" placeholder="Phone Number" size="53px"/><br> 
       <input type="email" name="email" placeholder="Email Address" size="53px"/><br> 
       <input type="email" name="confirmemail" placeholder="Confirm Email" size="53px"/><br> 
       <input type="submit" name="submitButton" /> 
</form> 

和我的PHP文件中的最好的,我可以尝试得到的是:

<?php 

if($_POST["submit"]) { 
$recipient="[email protected]"; 
$subject="Form to email message"; 
$sender=$_POST["Email sender"]; 
$senderEmail=$_POST["[email protected]"]; 
$message=$_POST["This is my message"]; 

$mailBody="Name: $sender\nEmail: $senderEmail\n\n$message"; 

mail($recipient, $subject, $mailBody, "From: $sender <$senderEmail>"); 

$thankYou="<p>Thank you! Your message has been sent.</p>"; 
} 

?> 

当我点击我的提交按钮,我得到的是这样的:

enter image description here

如果你们中的任何人都可以帮我解决这个问题,那么我将非常感谢。

谢谢

+5

您使用的是网络服务器?您需要一台服务器来运行PHP脚本。 – Barmar

+0

你必须使用网络服务器吗?我只在本地运行它。 – grmackintosh

+0

grmackintosh - 是的。下载并安装[WAMP](http://www.wampserver.com/en/)在您的Windows计算机上进行PHP开发。然后回来编辑您的问题,并在运行代码时产生任何错误。 –

回答

0

只有在通过网络服务器访问脚本时才执行脚本。您不能使用本地文件来运行脚本。使用file://path访问脚本将只显示脚本的内容,而不运行它。

-1

除此之外,你可能不运行的Web服务器支持PHP的事实,

你可能缺少一个SMTP服务器,您需要在代码中发送电子邮件。 Google提供有关其smtp的信息。

服务器地址:smtp.gmail.com

端口: 465(需要SSL)587(TLS需要)