我的联系页面上有一个联系表格,这是一个php页面。我正在收集用户的请求并尝试将其邮寄到me@mydomain.com。但是,我尝试了所有不同的方法,但无法使用PHP发送邮件。我是php的新手,我正在努力学习这门语言。这是代码示例。
这是我的HTML
<h2>Your Details</h2></br>
<div class="form_row">
<input type="text" class="form_input" name="name" id="txtName" placeholder="Your Name" />
</div>
<div class="form_row">
<input type="text" class="form_input" name="phone" id="txtPhone" placeholder="Phone Number" />
</div>
<div class="form_row">
<input type="text" class="form_input" name="email" id="txtEmail" placeholder="Email" />
</div>
<div class="form_row">
<textarea class="form_textarea" name="message" id="txtMessage" placeholder="Provide as much information you can regarding the project."></textarea>
<p><input type="submit" id="submit" class="button" value="Send"/></p>
</div>
这是我的php脚本
<?php
if(isset($_POST['submit']))
{
$to = "harish.upadhyayula@ritchsystems.com";
$subject = 'Request for quote from - ritch systems website.';
$from = 'Surekha';
$phone = '410-555-4988';
$message = 'Testing php mail by hard coding.';
$headers = "From: ".$from."\r\n" .
"Phone: ".$phone;
ini_set("sendmail_from", $from);
if(mail( $to, $subject, $message, $headers ))
{
echo 'Mail Sent';
}
else {echo 'Something is wrong!';}
}
?>
答案 0 :(得分:3)
在不在localhost上的服务器上尝试此类型(无法发送邮件)
$to = 'rsharma@gmail.com';
$subject = 'Thanks for Registering on Dota Pub Stars!';
$message = 'your msg';
$headers = "MIME-Version: 1.0 \r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n"; //sending html
$headers .= "From: $from\r\n";
mail($to, $subject, $message, $headers);