Can not send mail from html form

Wednesday, November 4, 2015

I have been working on a single page website. It have like 8 pages. Last one is contact form. I have a PHP function "send_mail.php" that posts the data to my gmail account. This code is only working if i put it in a separate html but if i call this function through my index.html, it doesnt send the email.



<section id="contact">





Contact Info















<input type="submit" value="Submit" />
</form>
</div>
</div>
</div>
</div>
</div>
</section><!--/#bottom-->


and then my php



    <?php function isInjected($str) {
$injections = array('(\n+)',
'(\r+)',
'(\t+)',
'(%0A+)',
'(%0D+)',
'(%08+)',
'(%09+)'
);
$inject = join('|', $injections);
$inject = "/$inject/i";
if(preg_match($inject,$str)) {
return true;
}
else {
return false;
}}$email_address = $_REQUEST['email_address'] ;
$name = $_REQUEST['user_name'] ;
$subject = $_REQUEST['email_subject'] ;
$comments = $_REQUEST['comments'] ;

// If the user tries to access this script directly, redirect them to feedback form,
if (!isset($_REQUEST['email_address'])) {
header( "Location: index.html" );
}

// If the form fields are empty, redirect to the error page.
elseif (empty($email_address) || empty($comments)) {
header( "Location: index.html" );
}

// If email injection is detected, redirect to the error page.
elseif ( isInjected($email_address) ) {
header( "Location: index.html" );
}

// If we passed all previous tests, send the email!
else {
mail( "abcd@gmail.com", $subject,
$comments, "From: $email_address" );
header( "Location: index.html" );
}
?>


Somehow I found the error location but couldnt narrow it down. If I remove my js references, i can send email though.

0 comments:

Post a Comment