mail.php problem... can anyone help please?

neilmac

Suspended / Banned
Messages
1,053
Name
Neil McLeland
Edit My Images
Yes
I am developing a website and have copied a mail.php page from another of my sites that does work. I have just changed the recipient email address to suit this new site.

I have created a good_url here which displays when the contact form here is submitted.

However nothing appears at the receiving end so something must be missing/wrong etc.

The mail script I'm using is here although this does work on my other sites :shrug:.

Could someone please have a look at it, I'm pretty sure I must be missing something obvious but I just can't see it :bang:

Thanks in advance

Neil

Oh, and if you're feeling generous with advice can you also tell me how to make a tickbox on the contact form part of the validation process before submitting? Ta
 
I'll have a peek now for you. ;)
 
have you put tags in your mail.php to allow it to be viewed as code? Because if not then we should not be able to read it as code it should be parsed.. this suggests your server does not have PHP installed?
 
Neil, can you post the original mail.php code into code tags here? Remember, don't view it in the browser and take it from the source, take it from the un-parsed code from the root file.


[code] Paste the code here between these two tags?[/code]
 
Hi, thanks for taking the time. Does this make sense?

Code:
<?php

    /*
    INSTRUCTIONS FOR USE
    
    1. Install this script in your Root directory (save it as mail.php)
    2. Create a form and insert one hidden field, called "good_url" with a value of e.g. thankyou.htm/ thankyou.php or any other page you wish to call it (you will create this thankyou page next)
    3. Make the ACTION of the form point to this page
    4. Create a thankyou.htm/ thankyou.php page (the same name as your "good_url" [item 2 above]).
    5. Amend the config section below and change the 'YOUR_EMAIL_ADDRESS' to your email address (where you wish to pick up the form results! 
    
    */
    
    /*
    CONFIG
    Set the line
    $_email_recipient = "YOUR_EMAIL_ADDRESS";
    where YOUR_EMAIL_ADDRESS is your email address!!
    */
    
    $_email_recipient = "enquiries@spanish-village-property.co.uk";
    
    /* end fo config */
    
    
    
    
    
    
    
    $_referer = $_SERVER['HTTP_REFERER'];
    
    $_this_server = "http:\/\/" . $_SERVER['SERVER_NAME'];
    
    if (preg_match ("/^" . $_this_server . "/", $_referer))**
        
        $_message .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body><table>';
        
        foreach ($_POST as $_key => $_value)**
            
            if ($_key == "good_url")**
                
                $_good_url = $_value;
                
            ** else **
            
                $_message .= "<tr><th>$_key: </th><td>$_value</td></tr>";
                
            **
            
        **
        
        $_message .= sprintf ("<tr><td colspan=\"2\">&nbsp;</td></tr><tr><th>Sent from:</th><td>%s</td></tr>", $_SERVER['HTTP_REFERER']);
        
        $_message .= "</table></body>
</html>";
        
        $_subject = "Spanish village property enquiry";
        
        // To send HTML mail, the Content-type header must be set
        $headers  = 'MIME-Version: 1.0' . "\r\n";
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
        
        // Additional headers
        $headers .= "To: $_email_recipient <$_email_recipient>\r\n";
        $headers .= "From: Spanish Village Property form <donotreply@mysite.com>\r\n";
                
        if (file_exists ($_good_url))**
        
            if (@mail ($_email_recipient, $_subject, $_message, $headers))**
            
                header ("location:$_good_url");
                
            ** else **
            
                print ("Could not send email to: $_email_recipient");
                
            **
            
        ** else **
                
            print ("Please specify a valid 'good_url'");
            
        **
        
    **
    
    exit;
    
?>

Thanks

Neil
 
Isn't that breach of copyright?;)
 
have you put tags in your mail.php to allow it to be viewed as code? Because if not then we should not be able to read it as code it should be parsed.. this suggests your server does not have PHP installed?

No, I just pasted the code onto the design view so it could be viewed on here. I've done it properly now as per my last post (I think) :D
 
No, I just pasted the code onto the design view so it could be viewed on here. I've done it properly now as per my last post (I think) :D

Yeah thats fine fella. ;)

Nothing obvious jumps out at me to be honest, although I'm attempting to juggle work with blatant skiving, it's a hard act but I try my best.

Hmmmm, not sure...:suspect:

Any legal eagles help out?

Lol nice choice in Avatar! ;)

I think I first spotted it on detailingworld.co.uk goodness knows how long ago and it's been my faithful side kick ever since! :D Seeing as you had it first I'll bow out gracefully and take a new sidekick onto the forum with me instead. ;)
 
Nah, it is time I had a change, so in my new "Be nice to a newbie" guise, it`s all yours fella.......:lol:
 
Nah, it is time I had a change, so in my new "Be nice to a newbie" guise, it`s all yours fella.......:lol:

Nah it'll only confuse people who associate the avatar with you, the last thing I need is a forum full of enraged posters hunting me down pitchfork style! ;)
 
Nah it'll only confuse people who associate the avatar with you, the last thing I need is a forum full of enraged posters hunting me down pitchfork style! ;)

Harsh, but true, probably...........:suspect:

:lol: you must already know Fracster then :D

:exit:

OI?...................:D
 
No, I just pasted the code onto the design view so it could be viewed on here. I've done it properly now as per my last post (I think) :D

In that case when i click on your link to open mail.php I should not be presented with the code.. It should execute mail.php.. not display it. That to me suggests your webserver does not support php at the moment. Do you have a control panel where you can install services etc?

Create a new file called phpinfo.php (or anything you like as long as it is .php) and put this as the contents

Code:
<?php phpinfo (); ?>

Then upload/open that page and it will tell you if and what version of php is installed.
 
In that case when i click on your link to open mail.php I should not be presented with the code.. It should execute mail.php.. not display it. That to me suggests your webserver does not support php at the moment. Do you have a control panel where you can install services etc?

Create a new file called phpinfo.php (or anything you like as long as it is .php) and put this as the contents

Code:
<?php phpinfo (); ?>
Then upload/open that page and it will tell you if and what version of php is installed.

Hi thanks for that, I've followed your advice and it tells me
PHP Version 5.2.6


The code was only visible in the original link because I pasted it there, I've removed it now to make my mail.php as it was. I don't think you'll see anything now if you follow that link.

Cheers Neil
 
Oh sorry mate I get you now.. Design view in your web software.. That makes sense now. Sorry being blonde :D

Will start again.. away to have a proper nosey :D
 
Oh sorry mate I get you now.. Design view in your web software.. That makes sense now. Sorry being blonde :D

Will start again.. away to have a proper nosey :D

No probs.... appreciate your help ;)
 
This site's wordfilter is knackering your code.. it is replaces curly brackets with **'s

Can you upload a mail.txt to your site :)
 
Is your site on a different server?

If its on a different server to the one thats working and everything is working how it should be, and your not getting any emails, then Mail might not be enabled. Have a look in your phpinfo.php file that you uploaded. Search for 'mail' (ctrl+f for search) on that page.
 
This site's wordfilter is knackering your code.. it is replaces curly brackets with **'s

Can you upload a mail.txt to your site :)

This any help?

:thumbs:
 
As per surrealillusions its as if the mail function isn't enabled..

Try this..

Code:
<?php

$Name = "Test Script"; //senders name
$email = "donotreply@spanish-village-property.co.uk"; //senders e-mail adress
$recipient = "enquiries@spanish-village-property.co.uk"; //recipient
$mail_body = "Message Body"; //mail body
$subject = "Test E-Mail"; //subject
$header = "From: ". $Name . " <" . $email . ">\r\n"; //optional headerfields

mail($recipient, $subject, $mail_body, $header); //mail command :)
?>

It wont show anything on screen but will use the mail function without all the surrounding checks applies by your mail.php but will let you know that the mail function is working.

(You might have had a test e-mail already.. i forgot to edit your address, it was sent from my server around 13:20)
 
As per surrealillusions its as if the mail function isn't enabled..

Try this..

Code:
<?php

$Name = "Test Script"; //senders name
$email = "donotreply@spanish-village-property.co.uk"; //senders e-mail adress
$recipient = "enquiries@spanish-village-property.co.uk"; //recipient
$mail_body = "Message Body"; //mail body
$subject = "Test E-Mail"; //subject
$header = "From: ". $Name . " <" . $email . ">\r\n"; //optional headerfields

mail($recipient, $subject, $mail_body, $header); //mail command :)
?>
It wont show anything on screen but will use the mail function without all the surrounding checks applies by your mail.php but will let you know that the mail function is working.

(You might have had a test e-mail already.. i forgot to edit your address, it was sent from my server around 13:20)

Just got back in. No, no test email has arrived :(

I'll try your recommendation above.

Thanks again
 
Do you have any spam filters? Maybe because the e-mail is coming as from @spanish-village-property.co.uk it thinks that is junk?

Just another thing to consider.. (best way to try it is use a hotmail/gmail address or similar to test it).
 
As per surrealillusions its as if the mail function isn't enabled..

Try this..

Code:
<?php

$Name = "Test Script"; //senders name
$email = "donotreply@spanish-village-property.co.uk"; //senders e-mail adress
$recipient = "enquiries@spanish-village-property.co.uk"; //recipient
$mail_body = "Message Body"; //mail body
$subject = "Test E-Mail"; //subject
$header = "From: ". $Name . " <" . $email . ">\r\n"; //optional headerfields

mail($recipient, $subject, $mail_body, $header); //mail command :)
?>
It wont show anything on screen but will use the mail function without all the surrounding checks applies by your mail.php but will let you know that the mail function is working.

(You might have had a test e-mail already.. i forgot to edit your address, it was sent from my server around 13:20)

OK, tried this today (that is, I replaced my mail.php code with the example you kindly gave and uploaded it, then tried to send an enquiry via my contact form) and still nothing. There is no hint of anything being wrong - just the enquiry doesn't arrive :shrug:

I sent a support ticket to my hosting company in the vague hope something might need to be enabled and this was their reply

"In order for a script to send emails you need to make sure that the following is followed and correct. You only have root@spanish-village-property.co.uk so you must use that in your script to send to or from.

1) The domain must resolve to our services for both Email and Website. This usually means you must use our name servers, or, at least have the A and MX record pointing at our servers here. If the email doesn’t resolve here a script will fail.
2) You must make sure that your script references a mailbox on your domain. This will usually be root@(your domain) or a mailbox you have created if you are using a Power User account.
3) You also need to ensure that you are hosted on the right server. Typically customers are on a Linux server for PHP and Windows server for ASP. If you have to run PHP on a Windows server you may run into problems due to restrictions.
4) You need to ensure that the script is written correctly and secure. If the script is left open for abuse then you may find that emails are blocked or your site suspended.
5) You need to ensure that the script is not trying to send more than 150 emails per day. This is the limit set to all mailboxes."


Nothing here seems to give any clues.....

I have since made sure that the email address in my mail.php is set up properly as a standard email address and not a forwarder as before. Still nothing.

What I really don't get is that my contact forms and mail.php and hosting are the same for all my sites (except for individual email addresses) and they work :bang:

Neil
 
The mail.php I supplied is only a test and doesn't require the form.. If you just go to the url of mail.php that will be enough to send a test mail to you.. You can see from what I supplied that all it does is sets up the parameters then calls the "mail" function passing those parameters.

If you are on a windows server often the host allows you to switch to linux at the touch of a button, this should be in the control panel of your site if available.

are they the same host for all your sites?
 
The mail.php I supplied is only a test and doesn't require the form.. If you just go to the url of mail.php that will be enough to send a test mail to you.. You can see from what I supplied that all it does is sets up the parameters then calls the "mail" function passing those parameters.

If you are on a windows server often the host allows you to switch to linux at the touch of a button, this should be in the control panel of your site if available.

are they the same host for all your sites?

Yes, same host and all on Linux servers already....
 
In order for a script to send emails you need to make sure that the following is followed and correct. You only have root@spanish-village-property.co.uk so you must use that in your script to send to or from.

1) The domain must resolve to our services for both Email and Website. This usually means you must use our name servers, or, at least have the A and MX record pointing at our servers here. If the email doesn&#8217;t resolve here a script will fail.
2) You must make sure that your script references a mailbox on your domain.

That might be your problem. Does your email address actually exist? If not, create the donotreply@spanish-village-property.co.uk, or at least setup a forwarder so any email that goes to that address goes to your email instead.

:)
 
That might be your problem. Does your email address actually exist? If not, create the donotreply@spanish-village-property.co.uk, or at least setup a forwarder so any email that goes to that address goes to your email instead.

:)

Hi, thanks for your suggestion, 'enquiries@' exists so I have just set up a 'donotreply' email address so will try it again in a little while. :thumbs:
 
Just another thing to consider.. (best way to try it is use a hotmail/gmail address or similar to test it).

Still nothing. However, I have now tried substituting the proper email address to my old Hotmail one and it works straight away!

....... then Mail might not be enabled. Have a look in your phpinfo.php file that you uploaded. Search for 'mail' (ctrl+f for search) on that page.

Think this might be going the right way now (thanks to you guys). As my brain is completely fried with this now, would you mind giving me easy step by step instructions to get Mail enabled please?

Tried the 'mail' search and got 3 entries containing 'mail'

mail.force_extra_parameters no value no value
sendmail_from no value no value
sendmail_path /usr/sbin/sendmail -t -i /usr/sbin/sendmail -t -i

Mean anything?

Cheers,

Neil
 
Thanks again for all your efforts :)

I've just checked my control panel at my hosting company and both 'donotreply@spanish-village-property.co.uk' and 'enquiries@spanish-village-property.co.uk' show as set up email addresses - but it still doesn't work.

I can receive direct emails to enquiries@spanish-village-property.co.uk though :shrug:

At least the Hotmail system does work so all is not lost.

Cheers

Neil
 
is mail.php in the right place?
what permissions? If you stick in a bit of debug to write something to a log file does that happen? Just looking to seperate script execution and email issues.
 
is mail.php in the right place?
what permissions? If you stick in a bit of debug to write something to a log file does that happen? Just looking to seperate script execution and email issues.

Hi, thanks for your suggestions although they are above my knowledge level :shrug:

Permissions, debug, log file - straight over my head :), sorry.

Appreciate your effort though.

Neil
 
At the top of the PHP file, just under <?php add the following:
PHP:
error_reporting(E_ALL);
Then post any errors the script returns.
 
At the top of the PHP file, just under <?php add the following:

error_reporting(E_ALL);

Then post any errors the script returns.

Thanks MattF, I've added the code, uploaded the page and viewed in a browser. This is what is displayed

Notice: Undefined index: HTTP_REFERER in /home/fhlinux137/s/spanish-village-property.co.uk/user/htdocs/mail.php on line 31

Any good?

Neil
 
I get exactly the same Neil..

I have setup a mailbox and I can send from hotmail to that mailbox in a split second..
I have also set up the form on my site but altered it to send to my hotmail and streamline address.. The hotmail one is there by the time i check and the streamline one doesn't appear.

So sending is not an issue.. it's only when you try to send to your own domain as far as I can tell.

I cant see why they would block e-mails from their server to their server unless it thought it was some sort of spoofing attack.

I will see what I can come up with.
 
Got it!

in mail.php find the line which sends the mail..

Code:
if (@mail ($_email_recipient, $_subject, $_message, $headers

It will look something like the above but the word censor may change bits..

In that line find "$headers"

and after that add..
Code:
, "-fenquiries@spanish-village-property.co.uk"

so that you end up with..

Code:
if (@mail ($_email_recipient, $_subject, $_message, $headers, "-fenquiries@spanish-village-property.co.uk"))X

(Where X is the curly open bracket that will already be there).

If you set the recipient email at the top of the mail.php to enquiries@spanish-village-property.co.uk it should go straight through!

G
 
Got it!

in mail.php find the line which sends the mail..

Code:
if (@mail ($_email_recipient, $_subject, $_message, $headers
It will look something like the above but the word censor may change bits..

In that line find "$headers"

and after that add..
Code:
, "-fenquiries@spanish-village-property.co.uk"
so that you end up with..

Code:
if (@mail ($_email_recipient, $_subject, $_message, $headers, "-fenquiries@spanish-village-property.co.uk"))X
(Where X is the curly open bracket that will already be there).

If you set the recipient email at the top of the mail.php to enquiries@spanish-village-property.co.uk it should go straight through!

G

That's brilliant Graeme! Thanks - I'll try it out as soon as I'm back home.

Thanks again :thumbs:

Neil
 
Back
Top