this question has answer here:
hi guys developing site , producing email form using php, had various issues before such " failed connect mailserver @ "local host" port 25. verify smtp etc." result potential solution make site online, therefore have , php code inserted in live site , error did disappear no mail sent email address listed. have been working on form week , tried out various different forms available on internet still no email received. php code below:
updated php code
<?php //checks header injection function has_header_injection($str){ return preg_match("/[\r\n]/",$str); } if(isset($_post['contact_submit'])){ $name = trim($_post['name']); $email = trim($_post['email']); $msg = $_post['message']; //check see if name or email have header injecion if(has_header_injection($name) || has_header_injection ($email)){ die(); //if true kill script } if(!$name || !$email || !$msg){ echo '<h4 class = "error"> fields required </h4> <a href = "contact.php" class = "button block"> go bacck , try again </a>'; exit; } //add recipient email variable $to = "mahdi.mashrafi@yahoo.com"; $subject = "$name sent message via contact form"; $message = "name: $name\r\n"; $message .= "email: $email\r\n"; $message .= "message:\r\n$msg"; $message = wordwrap($message, 72); //set mail headers variable $headers = "mime-version: 1.0\r\n"; $headers .="content-type: text/plain; charset=iso-8859-1\r\n"; $headers .= "from: $name <$email> \r\n"; $headers .= "x-priority: 1\r\n"; $headers .= "x-msmail-priority:high\r\n\r\n"; $status = mail ($to, $subject , $message , $headers); var_dump($status); ?> **html form** <h5>thanks contacting </h5> <p>please allow 24 housr respond</p> <p> <a href = "/final" class = "bitton block">« go homepage </a> </p> <?php } else {?> <form method = "post" action = "" id = "contact-form"> <label = "name">your name </label> <input type = "text" id = "name" name = "name"> <label = "email">your email</label> <input type = "email" id = "email" name = "email"> <label = "message">and message </label> <textarea type = "message" id = "message" name = "message"></textarea> <input type = "submit" class = "button next" name = "contact_submit" value ="send message"> </form> <?php } ?> </div>
any tutorials on email form great , potential solutions hugely appreciated. have literally no idea why mail isnt being sent/recieved.
--------updated php code has been updated -------
try following debug error message. change
mail ($to, $subject , $message , $headers);
to
$status = mail ($to, $subject , $message , $headers); var_dump($status);
if $status
false means have error sending mail. let know how goes.
update: https://stackoverflow.com/a/24644450/688924 has description of possibly go wrong in mail()
function. follow instructions provided there. after following instruction find mail()
not working suggest try alternatives phpmailer
, swiftmailer
external libraries.
Comments
Post a Comment