Webmaster Forum

Go Back   Webmaster Forum > Web Development > Coding Forum

Coding Forum Problems with your code? Discuss coding issues, including JavaScript, PHP & MySQL, HTML & CSS, Flash & ActionScript, and more.


Closed Thread
 
Thread Tools Display Modes
Share |
  #1  
Old 07-19-2016, 07:33 AM
Eelco85 Eelco85 is offline
Junior Member
 
Join Date: 07-19-16
Posts: 7
iTrader: 0 / 0%
What goes wrong in my php email form?

Hi there,

I'm not a good webmaster. I'm a beginner.
I downloaded a template email form from a website. Everything is working except the sending of the form. I get an error: "Could not send mail! Please check your PHP mail configuration."

My website host says that my smtp server is this: smtp.transip.email

Can anybody help me with this. Spend my whole weekend on it. Enoying!!

This is my html code:

Code:
<form class="ajax-form" id="contactForm" method="post" action="assets/php/contact.php"> <div class="form-group"> <input type="text" class="form-control" id="name" name="name" placeholder="Jouw naam..." value="" required> </div> <div class="form-group"> <input type="email" class="form-control" id="email" name="email" placeholder="Jouw email..." value="" required> </div> <div class="form-group"> <input type="phone" class="form-control" id="phone" name="phone" placeholder="Jouw telefoonnummer..." value="" required> </div> <div class="form-group"> <textarea class="form-control" rows="4" name="message" placeholder="Jouw bericht..." required></textarea> </div> <div class="form-group"> <button type="submit" name="submit" class="btn btn-default"><i class="fa fa-paper-plane fa-fw"></i>Verzenden</button> </div> </form>
And this is my PHP code:

Code:
<?php header('Content-type: application/json'); error_reporting(-1); ini_set("log_errors", "1"); if($_POST) { $to_email = "info@force10.tv"; //Recipient email, Replace with own email here //check if its an ajax request, exit if not if(!isset($_SERVER['HTTP_X_REQUESTED_WITH']) AND strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') { $output = json_encode(array( //create JSON data 'type'=>'error', 'text' => 'Sorry Request must be Ajax POST' )); die($output); //exit script outputting json data } //Sanitize input data using PHP filter_var(). $user_name = filter_var($_POST["name"], FILTER_SANITIZE_STRING); $user_email = filter_var($_POST["email"], FILTER_SANITIZE_EMAIL); $phone_number = filter_var($_POST["phone"], FILTER_SANITIZE_NUMBER_INT); $message = filter_var($_POST["message"], FILTER_SANITIZE_STRING); //additional php validation if(strlen($user_name)<4){ // If length is less than 4 it will output JSON error. $output = json_encode(array('type'=>'error', 'text' => 'Naam is te kort of leeg')); die($output); } if(!filter_var($user_email, FILTER_VALIDATE_EMAIL)){ //email validation $output = json_encode(array('type'=>'error', 'text' => 'Vul alsjeblieft een geldig email in')); die($output); } if(!filter_var($phone_number, FILTER_SANITIZE_NUMBER_FLOAT)){ //check for valid numbers in phone number field $output = json_encode(array('type'=>'error', 'text' => 'Voer alleen cijfers in')); die($output); } if(strlen($message)<3){ //check emtpy message $output = json_encode(array('type'=>'error', 'text' => 'Sorry, een te kort bericht. Vul iets in')); die($output); } //email subject $subject ='Bericht via de website Force 10'; //email body $message_body = $message."\r\n\r\n-".$user_name."\r\n\r\nEmail : ".$user_email."\r\nPhone Number : ". $phone_number ; //proceed with PHP email. $headers = 'From: '.$user_name.'<'.$user_email.'>'."\r\n" . 'Reply-To: '.$user_name.'<'.$user_email.'>' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); $send_mail = mail($to_email, $subject, $message_body, $headers); if(!$send_mail) { //If mail couldn't be sent output error. Check your PHP email configuration (if it ever happens) $output = json_encode(array('type'=>'error', 'text' => 'Could not send mail! Please check your PHP mail configuration.')); die($output); }else{ $output = json_encode(array('type'=>'success', 'text' => 'Hi '.$user_name .', Bedankt voor je bericht. We zullen z.s.m contact opnemen.')); die($output); } } ?>
 

Advertisement

Advertisement

  #2  
Old 07-19-2016, 10:42 AM
ScriptMan's Avatar
ScriptMan ScriptMan is online now
Super Moderator
 
Join Date: 02-10-07
Location: Central Kentucky
Posts: 14,023
iTrader: 4 / 100%
I'm hardly a php pro but php sendmail does not use the smtp server to send mail.

This line:
PHP Code:
$to_email       "info@force10.tv"//Recipient email, Replace with own email here 
should contain the email address you want the mail sent to. That must be a valid email address on your server.

And this line must match the location of the contact.php on your server:
PHP Code:
<form class="ajax-form" id="contactForm" method="post" action="assets/php/contact.php"
As this is currently set the form sends the data to the directory php which is under the directory assets and the file name is contct.php. Is that where you placed the file or is it in a different directory?

Last edited by ScriptMan; 07-19-2016 at 10:48 AM.
 
  #3  
Old 07-19-2016, 11:12 AM
Eelco85 Eelco85 is offline
Junior Member
 
Join Date: 07-19-16
Posts: 7
iTrader: 0 / 0%
Hi,

Thanks for helping me.

The email address info@ is valid. I double checked that. So that's not the problem.
The file contact.php is in the assets/php/ bin so that shouldn't give a problem too.
But, the form is still giving me the same error....

Do I have to add some SMTP parameters or something like that in the code?

I hope the solution is near! :-)
 
  #4  
Old 07-19-2016, 01:03 PM
Rob Whisonant's Avatar
Rob Whisonant Rob Whisonant is offline
Contributing Member
 
Join Date: 05-23-16
Location: Fort Lauderdale, FL
Posts: 75
iTrader: 0 / 0%
It sounds like send mail is not configured on your server. Tell your host that you are using the PHP mail function and that you need them to configure php.ini to suport it. Most hosts have this done already. For some reason it sounds like your host has not.
 
  #5  
Old 07-21-2016, 01:59 AM
Eelco85 Eelco85 is offline
Junior Member
 
Join Date: 07-19-16
Posts: 7
iTrader: 0 / 0%
Hi,

I again had contact with my host. Due to safety the form can not be sent from a different address. This should always be my own server address (in my case a @force10.tv address)

They say: "... your form is currently working like that the completed e-mail address (for example @hotmail address what you call) is used as the sender address, but this should not (the from: address) be the sender address but, in this case, a @force10.tv address, this should be set as a static value. "

When I fill in a @force10.tv address in the form, the form is submitted it.

Further, they say, "... but you will still need to modify the form itself so that the sender (the FROM and REPLY-TO address) is always an @force10.tv address."

But what do I have to do in the php code to add the From: @force10.tv address? How and which parameters do i have to add in the code?

Can someone help me with adding / inserting these parameters into the code?

Thank you very much thanks!

Greeting,
Eelco
 
  #6  
Old 07-21-2016, 04:44 AM
ScriptMan's Avatar
ScriptMan ScriptMan is online now
Super Moderator
 
Join Date: 02-10-07
Location: Central Kentucky
Posts: 14,023
iTrader: 4 / 100%
That is going to require some mods. It is the message headers you need to change but you won't be able to contact the people without their email address so you need to force the changes in the script portion and still capture the form data in the body of the message.

This is the part of the script that creates the headers:
PHP Code:
$headers 'From: '.$user_name.'<'.$user_email.'>'."\r\n" .
    
'Reply-To: '.$user_name.'<'.$user_email.'>' "\r\n" .
    
'X-Mailer: PHP/' phpversion(); 
You will need to force the correct values to $user_email and $user_name.

It appears that the info is already captured in the message body. In this section:
PHP Code:
//email body
    
$message_body $message."\r\n\r\n-".$user_name."\r\n\r\nEmail : ".$user_email."\r\nPhone Number : "$phone_number 
 
  #7  
Old 07-21-2016, 08:44 AM
Eelco85 Eelco85 is offline
Junior Member
 
Join Date: 07-19-16
Posts: 7
iTrader: 0 / 0%
Hi Scriptman,

So you telling me that I have to change the From: line from '.$user_name.' to my info@ address? I don't get it at this moment. Could you just specify your comment a little bit more? I'm more into HTML instead of PHP.

Thanks in advance.
 
  #8  
Old 07-21-2016, 10:28 AM
Eelco85 Eelco85 is offline
Junior Member
 
Join Date: 07-19-16
Posts: 7
iTrader: 0 / 0%
Quote:
Originally Posted by Eelco85 View Post
Hi Scriptman,

So you telling me that I have to change the From: line from '.$user_name.' to my info@ address? I don't get it at this moment. Could you just specify your comment a little bit more? I'm more into HTML instead of PHP.

Thanks in advance.
I changed this line but it still isn't working.

Code:
$headers = 'From: 'Force 10' <'info@force10.tv'>'."\r\n" . 'Reply-To: '.$user_name.' <'.$user_email.'>' . "\r\n" . 'X-Mailer: PHP/' . phpversion();
 
  #9  
Old 07-21-2016, 10:51 AM
Eelco85 Eelco85 is offline
Junior Member
 
Join Date: 07-19-16
Posts: 7
iTrader: 0 / 0%
Hi,

I changed the line again into
Code:
$headers = 'From: info@force10.tv' . "\r\n" . 'Reply-To: '.$user_name.' <'.$user_email.'>' . "\r\n" . 'X-Mailer: PHP/' . phpversion();
That is the solution. The form is working.

Thanks all!
 
Go Back   Webmaster Forum > Web Development > Coding Forum

Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Contact Form: What Am I Doing Wrong? scifibunny Coding Forum 8 09-26-2012 04:21 PM
Please Help with PHP Email Form semenov419 Coding Forum 0 07-07-2010 08:20 PM
need help with email form snowhunt Coding Forum 6 05-06-2010 01:06 AM
How to make form email to more than 1 email address MissTa Coding Forum 2 04-20-2010 09:27 AM
Email Me Form sweet-partners Web Design Lobby 1 02-13-2010 03:42 AM


V7N Network
Get exposure! V7N I Love Photography V7N SEO Blog V7N Directory


All times are GMT -7. The time now is 09:22 PM.
Powered by vBulletin
Copyright 2000-2014 Jelsoft Enterprises Limited.
Copyright © 2003 - 2018 VIX-WomensForum LLC