Contact Form info isn't arriving

I know this code isn’t the best, but I’d just like to figure out why after the Contact Form is filled in and submitted nothing arrives. Any help/suggestions will be appreciated.

Here’s the Form:

<form action='../submit.php' method='post' name='myform' onSubmit="return checkemail()">
<div class="row">
<div class="col-sm-12">
<textarea name="message" value="placeholder text" input type="text" onfocus="'#f2f2f2';
this.value='';" style="color: #f5f5f5;"/>Contact us - Enter your message here...</textarea>

<input class="form-control" type="text" name="name" maxlength="50" style="width:500px; height:60px"; placeholder="Name">
<input class="form-control" type="text" name="email" maxlength="50" style="width:500px; height:60px"; placeholder="Email">

<input class="btn btn-action" type='submit' value="Send Message" style="width:512px; height:60px; display:inline;">

And here’s submit.php:

// if the url field is empty
if(isset($_POST['url']) && $_POST['url'] == ''){

// put your email address here
$youremail = '';

$body = "ContactForm:
Name:  $_POST[name]
E-Mail: $_POST[email]
Message: $_POST[message]";

if( $_POST['email'] && !preg_match( "/[\r\n]/", $_POST['email']) ) {
  $headers = "From: $_POST[email]";
} else {
  $headers = "From: $youremail";

// finally, send the message
mail($youremail, 'Contact Form', $body, $headers );


// if no errors are set, continue

mail isn’t a reliable source to send emails. You should look into using PHPMailer.

I used to use PHPMailer, but I personally like SwiftMailer just a tad bit better. Though PHPMailer is fine also.

1 Like

All that aside, this line isn’t helping:

if(isset($_POST['url']) && $_POST['url'] == ''){

First off, you’re checking to see whether the $_POST variable called “url” exists, and is null. That’s not going to happen I don’t think - as far as I know, browsers simply don’t submit empty form variables.

Second, there isn’t a form field called “url” in your html code, so the line will never return true, so none of the code inside it will execute.


Thanks for your replies. I don’t really want to use PHPmailer, etc, I just want to fix what I have.

I just removed

if(isset($_POST['url']) && $_POST['url'] == '')

but still doesn’t deliver completed Form info.

Any additional help/suggestions will be welcomed.

Are you running this on a hosted website or on localhost?

Thanks for your reply.

It’s on a web hosted server

Okay, so the thing to do is make sure the mail() function actually works. Write a simple PHP script to send yourself a Hello world! email and see if you receive that. Only when you can be sure your web pages can send emails is it worth looking at the logic of your script.

Thanks for your help/suggestion.

Can you provide an example of “a simple PHP script to send yourself a Hello world! email”, I don’t know how to do that. (I didn’t write the code in my initial posting)

All you need is

mail($toemail, $subject, $body, $headers);

with suitable values for each of the variables.

Thanks for your reply.

I don’t know what to do with “suitable values for each of the variables”

Any additional help will be appreciated.

You are kidding? You’ve been working with PHP for some while. All you need to do is set $toemail to your email address; $subject to, say, “Hello world”; and $body to “Hello world” for the want of anything better.

Forget about $headers, just use

mail($toemail, $subject, $body);
1 Like

It means create variables that are appropriate for those passed as arguments in the mail function. However, it really would be wise to use something more reliable like PHPMailer or SwiftMailer. The reason behind this is that the default mail function can and most likely fail at random times. So in which case, you may or may not receive emails at any random point in time. PHPMailer and SwiftMailer are more reliable because the only reason why they would fail is if the credentials you provide are invalid or something is wrong with the setup conifguration. But they will almost 100% send emails without failing while the mail function sometimes doesn’t even send emails.

1 Like

Did you only remove it, or replace it with something more suitable?

    // Process form here...

^ This is how you check if a post request was made.

1 Like

You also might find an issue with sending the email using whatever from-address the user types in - some mail servers don’t allow that. IMO you should always send it from an address of your own, you can always use the “Reply-to” header to simplify sending a response to the user.

1 Like

Also, what’s in the checkMail() function? Seems as if the form won’t be submitted unless that runs as required.

1 Like

1 ) you have written

if(isset($_POST[‘url’]) && $_POST[‘url’] == ‘’)
this line has no logic instead of that you can use


2 ) mail($youremail, ‘Contact Form’, $body, $headers );
you are using mail function then question is that are you using it on local server or you have already hosted your website.

if you using it on local server then you can use php mailer or swift mailer function.

and if you using it on hosted server then you have to check your mail function is that working or not.
for testing it you can create test function and send mail on your own information then if it is working then you can use it on your project.

if not then you have to change some configuration in php.ini
for detail go here :

As noted, it’s on a hosted server.

Thanks for all the help

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.