PHP Mailer script Issue -
i real noob when comes php here problem -
the form "from address" reads rittehqkxm@dedi96.cpt1.host-h.net, , causes a) delivery failure notice , b) 1 cannot click "reply" address not person's address completed form.
here code can point out why happening , how fix it?
thank in advance
<?php /* set e-mail recipient */ $myemail = "info@ritter-accountants.co.za"; /* check form inputs using check_input function */ $name = check_input($_post['name'], "enter name"); $subject = check_input($_post['subject'], "enter subject"); $email = check_input($_post['email']); $message = check_input($_post['message'], "write message"); /* if e-mail not valid show error message */ if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email)) { show_error("e-mail address not valid"); } /* let's prepare message e-mail */ $message = " name: $name e-mail: $email subject: $subject message: $message "; /* send message using mail() function */ mail($myemail, $subject, $message); /* redirect visitor thank page */ header('location: thanks.html'); exit(); /* functions used */ function check_input($data, $problem='') { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); if ($problem && strlen($data) == 0) { show_error($problem); } return $data; } function show_error($myerror) { ?> <html> <body> <p>please correct following error:</p> <strong><?php echo $myerror; ?></strong> <p>hit button , try again</p> </body> </html> <?php exit(); } ?> and html
<form class="email" action="mailer.php" method="post"> <p align="center"><span class="style27"><strong>name:</strong></span></p> <div align="right"><span class="style21 link_title"><strong> <input style="width:50%;" type="text" name="name" /> </strong></span> </div> <p align="center"><span class="style27"><strong>e-mail:</strong></span></p> <div align="right"><span class="style21 link_title"><strong> <input style="width:50%;" type="text" name="email" /> </strong></span> </div> <p align="center"><span class="style27"><strong>subject:</strong></span></p> <div align="right"><span class="style21 link_title"><strong> <input style="width:50%;" type="text" name="subject" /> </strong></span> </div> <p align="center"><span class="style27"><strong>message: </strong></span></p> <div align="right"><span class="style21 link_title"><strong> <textarea style="width:50%;"= name="message"></textarea> </p> <input class="send" type="submit" value="send"> </strong></span> </div> </form>
your code not set sender email, default sendmail (or whatever sending mails server) user used sender header.
you can fix appending headers call php's mail function, fourth parameter.
php mail documentation's comments provides a straightforward example on how accomplish :
$headers = array(); $headers[] = "mime-version: 1.0"; $headers[] = "content-type: text/plain; charset=iso-8859-1"; $headers[] = "from: sender name <sender@domain.com>"; $headers[] = "bcc: jj chong <bcc@domain2.com>"; $headers[] = "reply-to: recipient name <receiver@domain3.com>"; $headers[] = "subject: {$subject}"; $headers[] = "x-mailer: php/".phpversion(); mail($to, $subject, $email, implode("\r\n", $headers)); i must add that, if in case hard coded recipient mail, not habit set address typed in form sender address.
a practice use system address sender , fill reply-to header email provided via form (the link above describes this). way can see message come , reply person talk you.
in case recipient inputed via form (eg. "tell friend" feature), mandatory use system address sender, since in countries may have legal issues if x people sends email y 1 using z's address sender (indentity theft).
Comments
Post a Comment