http://tutorialpot.com/2011/06/fancy-contact-form-with-inline-validation/#comment-1771
我想知道我在哪里放入我的电子邮件地址,以便用户可以发送电子邮件给我
提前致谢
<?PHP function checkLen($str,$len=2) //&len definens the minimun length of the input fIElds{ return isset($_POST[$str]) && mb_strlen(strip_Tags($_POST[$str]),"utf-8") > $len;}function checkEmail($str){ return preg_match("/^[\.A-z0-9_\-\+]+[@][A-z0-9_\-]+([.][A-z0-9_\-]+)+[A-z]{1,4}$/",$str);}foreach($_POST as $k=>$v){$_POST[$k]=stripslashes($_POST[$k]);$_POST[$k]=HTMLspecialchars(strip_Tags($_POST[$k]));}//session names must be same with that in contact form session_name("tpot_contact");@session_start();if (isset($_POST['send'])){ $err = array();if(!checkLen('name')) $err[]='The name fIEld is too short or empty!';if(!checkLen('email')) $err[]='The email fIEld is too short or empty!';else if(!checkEmail($_POST['email'])) $err[]='Your email is not valID!';if(!checkLen('subject')) $err[]='You have not selected a subject!';if(!checkLen('message')) $err[]='The message fIEld is too short or empty!';if((int)$_POST['captcha'] != $_SESSION['expected']) $err[]='Wrong security code!';if(count($err)){ $_SESSION['errStr'] = implode('<br />',$err); header('Location: '.$_SERVER['http_REFERER']); exit(); } //submission data $IP=$_SERVER['REMOTE_ADDR']; $name=$_POST['name']; $email=$_POST['email']; $date=(gmdate(" Y/m/d ")); $time = date('H:i:s'); $message=$_POST['message']; $from="noreply@tutorialpot.com"; $subject = " from ".$_POST['name']." | contact form"; $headers = "From: ".$from."\r\n"; $headers .= "Reply-to: ".$from."\r\n"; $headers = 'Content-type: text/HTML; charset=iso-8859-1' . "\r\n"; //checks whether send to my email address is set if ($cc == 1) { $headers .= 'Cc:'. $_POST['email']."\r\n"; } $msg = "<p><strong>name: </strong>" .$name. "</p> <p><strong>Email Address: </strong>" .$email. "</p> <p><strong>Enquiry: </strong>" .$_POST['subject']. "</p> <p><strong>Message: </strong>" .$message. "</p> <br/> <br/> <p>This message was sent from the IP Address:" .$ipaddress." on".$date. "at".$time."</p>"; if(@mail($email,$subject,$msg,$headers)) { $success=array(); $success[]='Your message has been sent! | Thank you'; $_SESSION['sent'] = implode('<br />',$success); header('Location: '.$_SERVER['http_REFERER']); exit(); } else{ $err[]='your message Could not be sent due to a network problem please try again.!'; $_SESSION['errStr'] = implode('<br />',$err); header('Location: '.$_SERVER['http_REFERER']); exit(); }}?> <div > <label for="name" >*name: </label> <input ID="name" name="name" type="text" autofocus="autofocus" placeholder="name"/><br /><br /> <label for="email">*Email</label> <input ID="email" name="email" type="text" placeholder="EMAIL" /><br /><br /> <label for="subect" >*Subject</label> <select ID="dropdown4" name="subject" > <option selected="selected" value="">--Choose--</option> <option value="Quote">Quote</option> <option value="Suggestion">Suggestion</option> <option value="Question">Question</option> <option value="Business Proposal">Business Proposal </option> <option value="Advertising">Advertising</option> <option value="Complaint">Complaint</option> <option value="Other">Other</option> </select><br /><br /> <label for="message" >*Message</label> <textarea rows="10" cols="15" name="message" ID="message" placeholder=" MESSAGE CONTENTS"></textarea><br /><br /> <legend>*Human Verification (HELP US figHT SPAM)</legend> <label for="captcha">25+9=</label> <input type="text" name="captcha" ID="captcha" maxlength="2" placeholder="DO A liTTLE MATH" /> <p> <input type='checkBox' ID='cc' name='cc' value='1' /> Send a copy to your email address </p> </div> <div > <input name="send" type="submit" ID="btnsubmit" /> <!--<input type="submit" name="send" ID="submit"/>--> </div></form>解决方法 这部分在邮件返回bool时发送消息.第一个参数是地址(见链接)
if(@mail($email,$headers))
http://php.net/manual/en/function.mail.php
在示例中,电子邮件将转到用户输入的地址,因为$email填充了已发布的值
$email=$_POST['email'];
但你可以硬编码到你想要的东西.
if(@mail('youremail@domain.com',$headers))总结
以上是内存溢出为你收集整理的从联系表单发送php电子邮件全部内容,希望文章能够帮你解决从联系表单发送php电子邮件所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)