2010-07-26 129 views
0

我的工作,如雅虎的Gmail电子邮件发送到任何收件人 我的代码是 接触形式从localhost发送邮件到Gmail或雅虎或rediff?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Email Form </title> 
</head> 
<body> 

<form method="post" action="sendeail.php"> 

<!-- DO NOT change ANY of the php sections --> 
<?php 
$ipi = getenv("REMOTE_ADDR"); 
$httprefi = getenv ("HTTP_REFERER"); 
$httpagenti = getenv ("HTTP_USER_AGENT"); 
?> 

<input type="hidden" name="ip" value="<?php echo $ipi ?>" /> 
<input type="hidden" name="httpref" value="<?php echo $httprefi ?>" /> 
<input type="hidden" name="httpagent" value="<?php echo $httpagenti ?>" /> 


Your Name: <br /> 
<input type="text" name="visitor" size="35" /> 
<br /> 
Your Email:<br /> 
<input type="text" name="visitormail" size="35" /> 
<br /> <br /> 
<br /> 
Attention:<br /> 
<select name="attn" size="1"> 
<option value=" Sales n Billing ">Sales n Billing </option> 
<option value=" General Support ">General Support </option> 
<option value=" Technical Support ">Technical Support </option> 
<option value=" Webmaster ">Webmaster </option> 
</select> 
<br /><br /> 
Mail Message: 
<br /> 
<textarea name="notes" rows="4" cols="40"></textarea> 
<br /> 
<input type="submit" value="Send Mail" /> 
<br /> 
</form> 

</body> 
</html> 

和senemail.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Sendemail Script</title> 
</head> 
<body> 

<!-- Reminder: Add the link for the 'next page' (at the bottom) --> 
<!-- Reminder: Change 'YourEmail' to Your real email --> 

<?php 

$ip = $_POST['ip']; 
$httpref = $_POST['httpref']; 
$httpagent = $_POST['httpagent']; 
$visitor = $_POST['visitor']; 
$visitormail = $_POST['visitormail']; 
$notes = $_POST['notes']; 
$attn = $_POST['attn']; 


if (eregi('http:', $notes)) { 
die ("Do NOT try that! ! "); 
} 
if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,"."))) 
{ 
echo "<h2>Use Back - Enter valid e-mail</h2>\n"; 
$badinput = "<h2>Feedback was NOT submitted</h2>\n"; 
echo $badinput; 
die ("Go back! ! "); 
} 

if(empty($visitor) || empty($visitormail) || empty($notes)) { 
echo "<h2>Use Back - fill in all fields</h2>\n"; 
die ("Use back! ! "); 
} 

$todayis = date("l, F j, Y, g:i a") ; 

$attn = $attn ; 
$subject = $attn; 

$notes = stripcslashes($notes); 

$message = " $todayis [EST] \n 
Attention: $attn \n 
Message: $notes \n 
From: $visitor ($visitormail)\n 
Additional Info : IP = $ip \n 
Browser Info: $httpagent \n 
Referral : $httpref \n 
"; 

$from = "From: $visitormail\r\n"; 


mail("YourEmail", $subject, $message, $from); 

?> 

<p align="center"> 
Date: <?php echo $todayis ?> 
<br /> 
Thank You : <?php echo $visitor ?> (<?php echo $visitormail ?>) 
<br /> 

Attention: <?php echo $attn ?> 
<br /> 
Message:<br /> 
<?php $notesout = str_replace("\r", "<br/>", $notes); 
echo $notesout; ?> 
<br /> 
<?php echo $ip ?> 

<br /><br /> 
<a href="contact.php"> Next Page </a> 
</p> 

</body> 
</html> 

我必须在我的本地制作,这样的变化是什么我将能够发送邮件...

谢谢。

回答

0

使用像PHPMailer这样的东西来做实际的电子邮件合成/发送。除此之外,您必须在本地运行SMTP服务器,或者访问其他地方(您的ISP的?,谷歌?)来处理邮件的物理发送。

+0

如果您打算自己发送这些消息,您还需要熟悉RFC 822。标题需要与消息正文一起正确格式化。 Gmail,雅虎等都会将您的电子邮件转为垃圾邮件,除非您努力正确格式化邮件。 如果您不关心如何正确格式化邮件,PHPMailed将是一个不错的选择。 – Chris 2010-07-26 10:34:47

0

您必须在php.ini中使用邮件()才能运行setup an smtp server

如果你只是测试你的脚本localy(不在生产​​服务器),使用你的ISP的SMTP将会有所斩获。

+0

不完全正确;您可以使用任何SMTP服务器,例如google,例如http://lifehacker.com/111166/how-to-use-gmail-as-your-smtp-server – 2010-07-26 11:42:20

+0

确实,我只是建议使用ISP的SMTP :) – Youssef 2010-07-26 11:59:47

相关问题