Jump to content

Recommended Posts

Several members of this forum recently helped me with a problem with my web host and i thank you.

I have xampp on my machine and while testing my php pages everything works perfectly including my thank you page. However when I upload the pages to the server all the fields works correctly and even the error message for the email format runs but when I hit the submit button the form simply returns to its initial state where all fields are blank and the neither the warning...'Sorry your mail could not be sent' or the thank you page appear. I'm not sure if I have the correct code for the authenticate staement. Could someone help me with this problem.formTest.php mail_process.php thanks.php

Link to comment
https://forums.phpfreaks.com/topic/298381-php-form-to-email-wont-send/
Share on other sites

You have a bunch of conditionals that could fail, but you're not handling that failure. My guess is that $mailSent is false.

 

You also have a syntax error here:

if(!mailSent) {
    $errors['mailfail'] = true;
}
Make sure you are developing with all errors turned on to prevent things like that.

I'm not sure why there is a syntax error in the above code. I'm a total newbie, a Photoshop and After Effects guy who does know some JavaScript and HTML but not php and I'm trying to do a website for great old 93 year old man.. When you say my conditionals could fail but I am not handling that I'm stumped. Also how do I turn errors on. I know its probably a really easy question but I don't know where to find the answer.

I'm not sure why there is a syntax error in the above code.

Hint: Variables must start with a $

 

When you say my conditionals could fail but I am not handling that I'm stumped.

Well, in a lot of places you're only handling the "true" part of the conditional. If it is "false", your script will just silently do nothing.

 

Also how do I turn errors on

Edit your php.ini and:

- set "error_reporting" to "-1"

- set "display_errors" to "On"

 

Make sure to restart Apache afterwards.

my error_reporting settings in php.ini are

 

; error_reporting
;   Default Value: E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED
;   Development Value: E_ALL
;   Production Value: E_ALL & ~E_DEPRECATED & ~E_STRICT
 

How do I set that to -1

 

Set display_errors to 'on'

Should look something like the following.

display_errors = On
;   Default Value: On
;   Development Value: On
;   Production Value: Off

Optionally, at the top of each php page you can set error handling with the following:

error_reporting(E_ALL);
ini_set('display_errors', 1);

my error_reporting settings in php.ini are

 

; error_reporting

;   Default Value: E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED

;   Development Value: E_ALL

;   Production Value: E_ALL & ~E_DEPRECATED & ~E_STRICT

 

How do I set that to -1

Remove the semicolon in front of error_reporting and set its value to -1.

error_reporting = -1
;   Default Value: E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED
;   Development Value: E_ALL
;   Production Value: E_ALL & ~E_DEPRECATED & ~E_STRICT
Do the same with display_errors (except its value will be set to On).

 

 

but its still not sending, more hints please

So then the call to mail() is failing and returning false. This is possibly due to a server configuration problem.

 

You can attempt to display the last error message and see if it gives any helpful clues.

if(!$mailSent) {
    echo '<pre>' . print_r(error_get_last(), true) . '</pre>';
    exit;
    $errors['mailfail'] = true;
}
This is just a temporary quick bodge for debugging purposes. After you figure out the problem you can remove those two new lines.

 

If you get any output from that please include it with your next reply.

Edited by scootstah

After all the changes were made, the first time I hit the submit button I got the thank you page. See attached

I ran it again and didn't get the thank you page, but did get the formTest.php with nothing on it. The form and the fields

were blank but browser still had formTest.php in the url window. Client reports no email receivedpost-179849-0-14147700-1443719148_thumb.jpg

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.