Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Tue Oct 15, 2013 6:12 am 
Offline
Junior Member

Joined: Tue Jan 12, 2010 8:06 am
Posts: 25
I've tested both my postfix

Code:
echo "Test mail from postfix" | mail -s "Test Postfix" admin@something.com

and PHP

Code:
php -a mail ('admin@something.com', "Test Postfix", "Test mail from postfix"); exit ();

and I'm receiving both the emails fine to my inbox. But my contact form @ http://www.villacalmia.co.uk/book_now.htm still isn't sending emails (even though it says it's been successfully sent) any ideas? - using the contact form from : http://www.freecontactform.com/email_form.php

I've set my contact form to send mail to testmail@primasmedia.co.uk (I have a catch-all so it should still come through to me) but I can't find any mention of the email address used in my logs (even when searching with grep)


Top
   
PostPosted: Tue Oct 15, 2013 7:08 am 
Offline
Senior Member

Joined: Mon Jan 02, 2012 12:45 pm
Posts: 365
Have you tried setting up the headers to be sent along with the form's email? If you set the 'bounce' header you may get the email back so you can see what's going on.
Code:
Return-Path: <bounced@yourdomain.com>

Looking at their code I see that they are suppressing any errors on the line that actually sends the email:
Code:
@mail($email_to, $email_subject, $email_message, $headers);

I'd suggest removing the '@' at the beginning of the line and turning errors on. I put these two lines of code at the top of my PHP scripts while debugging (and comment them out once things are working):
Code:
error_reporting(E_ALL) ;
ini_set('display_errors', 1) ;

You should see plenty of info now (including warnings, etc, caused by other lines of that script). Focus on the stuff related to the 'mail()' line.


Top
   
PostPosted: Tue Oct 15, 2013 7:20 am 
Offline
Junior Member

Joined: Tue Jan 12, 2010 8:06 am
Posts: 25
Like this? Still not getting any errors/emails back

Code:
<?php

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

if(isset($_POST['email'])) {
     
    // EDIT THE 2 LINES BELOW AS REQUIRED
    $email_to = "testmail123@primasmedia.co.uk";
    $email_subject = "Villacalmia.co.uk contact enquiry";
     
     
    function died($error) {
        // your error code can go here
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
        echo "These errors appear below.<br /><br />";
        echo $error."<br /><br />";
        echo "Please go back and fix these errors.<br /><br />";
        die();
    }
     
    // validation expected data exists
    if(!isset($_POST['first_name']) ||
        !isset($_POST['last_name']) ||
        !isset($_POST['email']) ||
        !isset($_POST['telephone']) ||
        !isset($_POST['comments'])) {
        died('We are sorry, but there appears to be a problem with the form you submitted.');       
    }
     
    $first_name = $_POST['first_name']; // required
    $last_name = $_POST['last_name']; // required
    $email_from = $_POST['email']; // required
    $telephone = $_POST['telephone']; // not required
    $comments = $_POST['comments']; // required
     
    $error_message = "";
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
  if(!preg_match($email_exp,$email_from)) {
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
  }
    $string_exp = "/^[A-Za-z .'-]+$/";
  if(!preg_match($string_exp,$first_name)) {
    $error_message .= 'The First Name you entered does not appear to be valid.<br />';
  }
  if(!preg_match($string_exp,$last_name)) {
    $error_message .= 'The Last Name you entered does not appear to be valid.<br />';
  }
  if(strlen($comments) < 2) {
    $error_message .= 'The Comments you entered do not appear to be valid.<br />';
  }
  if(strlen($error_message) > 0) {
    died($error_message);
  }
    $email_message = "Form details below.\n\n";
     
    function clean_string($string) {
      $bad = array("content-type","bcc:","to:","cc:","href");
      return str_replace($bad,"",$string);
    }
     
    $email_message .= "First Name: ".clean_string($first_name)."\n";
    $email_message .= "Last Name: ".clean_string($last_name)."\n";
    $email_message .= "Email: ".clean_string($email_from)."\n";
    $email_message .= "Telephone: ".clean_string($telephone)."\n";
    $email_message .= "Comments: ".clean_string($comments)."\n";
     
     
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'Return-Path: <bounced@primasmedia.co.uk>'.
'X-Mailer: PHP/' . phpversion();
mail($email_to, $email_subject, $email_message, $headers); 
?>
 
<!-- include your own success html here -->
 
Thank you for contacting us. We will be in touch with you very soon.
 
<?php
}
?>


Top
   
PostPosted: Tue Oct 15, 2013 7:26 am 
Offline
Senior Member

Joined: Sun Mar 07, 2010 7:47 pm
Posts: 1970
Website: http://www.rwky.net
Location: Earth
After you submit the form what's the last few lines of /var/log/mail.log ?

_________________
Paid support
How to ask for help
1. Give details of your problem
2. Post any errors
3. Post relevant logs.
4. Don't hide details i.e. your domain, it just makes things harder
5. Be polite or you'll be eaten by a grue


Top
   
PostPosted: Tue Oct 15, 2013 7:27 am 
Offline
Junior Member

Joined: Tue Jan 12, 2010 8:06 am
Posts: 25
obs wrote:
After you submit the form what's the last few lines of /var/log/mail.log ?


Nothing is added to mail.log when I submit the form


Top
   
PostPosted: Tue Oct 15, 2013 7:40 am 
Offline
Senior Member

Joined: Mon Jan 02, 2012 12:45 pm
Posts: 365
It's good that you've ruled out any PHP errors. The code doesn't actually check for successes or failure of the call to mail(). The PHP mail() command returns a boolean value (true for success, false for failure).

Try adding this code, replacing the line calling mail():
Code:
$success = mail($email_to, $email_subject, $email_message, $headers);
echo 'The email ' . (($success) ? 'worked!' : 'failed.') . '<br />';

If it says it failed there's something wrong with one (or more) of the variables sent to mail().


Top
   
PostPosted: Tue Oct 15, 2013 7:46 am 
Offline
Junior Member

Joined: Tue Jan 12, 2010 8:06 am
Posts: 25
Code:
The email worked!
Thank you for contacting us. We will be in touch with you very soon.


Still nothing in my inbox or logs though


Top
   
PostPosted: Tue Oct 15, 2013 8:09 am 
Offline
Senior Member

Joined: Sun Mar 07, 2010 7:47 pm
Posts: 1970
Website: http://www.rwky.net
Location: Earth
What's your sendmail_path php.ini setting? (You can get this from phpinfo();), make sure you test this from a web page not the command line since they use different php.ini files.

_________________
Paid support
How to ask for help
1. Give details of your problem
2. Post any errors
3. Post relevant logs.
4. Don't hide details i.e. your domain, it just makes things harder
5. Be polite or you'll be eaten by a grue


Top
   
PostPosted: Tue Oct 15, 2013 8:14 am 
Offline
Senior Member

Joined: Mon Jan 02, 2012 12:45 pm
Posts: 365
What happens when you use sendmail() instead of mail()? If that doesn't make a difference post your $email_to & $headers values. You may want to get them from "view page source" in your browser and put them between code tags to try to preserve some of their formatting.


Top
   
PostPosted: Tue Oct 15, 2013 9:16 am 
Offline
Junior Member

Joined: Tue Jan 12, 2010 8:06 am
Posts: 25
Main Street James wrote:
What happens when you use sendmail() instead of mail()? If that doesn't make a difference post your $email_to & $headers values. You may want to get them from "view page source" in your browser and put them between code tags to try to preserve some of their formatting.


When I try and use sendmail I get

Code:
Fatal error: Call to undefined function sendmail() in /var/www/villacalmia.co.uk/send_form_email.php on line 74


My email_to and header values are posted above, or are you asking for something else?


Top
   
PostPosted: Tue Oct 15, 2013 9:18 am 
Offline
Junior Member

Joined: Tue Jan 12, 2010 8:06 am
Posts: 25
obs wrote:
What's your sendmail_path php.ini setting? (You can get this from phpinfo();), make sure you test this from a web page not the command line since they use different php.ini files.


It's

Code:
sendmail_path = /usr/local/bin/phpsendmail
in my php.ini

Where should I place it on a webpage to get it to display and output? Should I just put it in a new test.php file with nothing but that in it or incorporate it into my send_from_email.php above?


Top
   
PostPosted: Tue Oct 15, 2013 9:36 am 
Offline
Senior Member

Joined: Sun Mar 07, 2010 7:47 pm
Posts: 1970
Website: http://www.rwky.net
Location: Earth
Well that looks wrong
Code:
sendmail_path = /usr/local/bin/phpsendmail
try changing it to /usr/sbin/sendmail -t -i

To create a phpinfo page just create a new page and put
Code:
<?php
phpinfo();
in it and load it from your browser.

_________________
Paid support
How to ask for help
1. Give details of your problem
2. Post any errors
3. Post relevant logs.
4. Don't hide details i.e. your domain, it just makes things harder
5. Be polite or you'll be eaten by a grue


Top
   
PostPosted: Tue Oct 15, 2013 9:43 am 
Offline
Junior Member

Joined: Tue Jan 12, 2010 8:06 am
Posts: 25
obs wrote:
Well that looks wrong
Code:
sendmail_path = /usr/local/bin/phpsendmail
try changing it to /usr/sbin/sendmail -t -i

To create a phpinfo page just create a new page and put
Code:
<?php
phpinfo();
in it and load it from your browser.


Okay, the path was the same when I created the php file so I went back to my php.ini file and changed it to what you specified. I'm still getting the message

Code:
The email worked!
Thank you for contacting us. We will be in touch with you very soon.


But no email is coming through, nothing in my logs either

phpinfo() here: http://villacalmia.co.uk/test.php


Top
   
PostPosted: Tue Oct 15, 2013 9:46 am 
Offline
Senior Member

Joined: Sun Mar 07, 2010 7:47 pm
Posts: 1970
Website: http://www.rwky.net
Location: Earth
Your sendmail_path hasn't changed make sure you're editing /etc/php5/apache2/php.ini and you've restarted apache.

_________________
Paid support
How to ask for help
1. Give details of your problem
2. Post any errors
3. Post relevant logs.
4. Don't hide details i.e. your domain, it just makes things harder
5. Be polite or you'll be eaten by a grue


Top
   
PostPosted: Tue Oct 15, 2013 9:47 am 
Offline
Junior Member

Joined: Tue Jan 12, 2010 8:06 am
Posts: 25
obs wrote:
Your sendmail_path hasn't changed make sure you're editing /etc/php5/apache2/php.ini and you've restarted apache.


Ah, my mistake! Thanks - that's it finally working :mrgreen:


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group