0

I use jQuery validate form plugin to receive email from my form contact. My code seems to run but I don't get mail. I see the message "Form sent" in WAMP. I have configured my SMTP server and I don't have error message from WAMP.

My form : http://jsfiddle.net/Xroad/2pLS2/24/

What's wrong ?

<?php
 if(isset($_POST) && isset($_POST['form_firstname']) && isset($_POST['form_name']) && isset($_POST['form_email']) && isset($_POST['form_telephone']) && isset($_POST['form_message'])) {
    extract($_POST);
    if(!empty($form_firstname) && !empty($form_name) && !empty($form_email) && !empty($form_telephone) && !empty($form_message)) {
        $to = "[email protected]"; // My real email
        $subjet = "Contact from the site";

        $msg = stripslashes($form_message);
        $msg = "A question came \n 
        Firstname : $form_firstname \n
        Name : $form_name \n
        Email : $form_email \n
        Message : $form_message";
        mail($to, $subjet, $msg);
        echo "Form sent";
    } else {
        echo "You have not filled in the field";
    }
 }
?>

<form id="form-general" action="php/traitement.php" method="post">
5
  • What's the return value of your call to mail()? Commented Mar 31, 2014 at 21:56
  • Have you checked your spam folder? Commented Mar 31, 2014 at 21:56
  • @jeroen I'm noob with PHP, it's necessary ? Commented Mar 31, 2014 at 21:57
  • Is script with only mail("[email protected]", "Contact from the site", "test"); working on your server? Commented Mar 31, 2014 at 22:02
  • @blue Such I don't get email Commented Mar 31, 2014 at 22:07

2 Answers 2

1

Well, in case a simple mail() function with no other code is not delivering mail to your inbox it seems like your SMTP has more to be configured.

Make mail("[email protected]", "Contact from the site", "test") work first and the rest of your code is probably good to go.

UPDATE

SMTP default value is localhost. According to me you're not able to resolve the domain SMTP (the one that is currently in your php.ini)! You could check that in console with telnet SMTP 25 (you might need to enable telnet first).

Anyway make sure you have a MTA on the other side - my best guess would be you need to call your system administrator and ask him about your SMTP host and port.

Just to keep you alert - in case you need to authenticate against your MTA you'll have to find another solution, because php's mail() (according to my knowledge) can't do that. Search for SwiftMailer and PhpMailer, both coming with a lot of examples.

Update 2

Well, sendmail.exe comes with its own configuration file, where you need to enter your smtp server, port and credentials!

Update 3

sendmail.exe TLS support hasn't been updated since 2008. The windows version has its last update 3 years ago and depending on which download you've chosen you might end up with even older version. While it works in general, there have been a number of reports for problems.

Even the author sendmail.exe is recommending MSMTP as a great open source alternative, and even blat as a more powerful tool. The only drawback I see is that those have a little more options and use different configuration format, which might look like harder to be configured.

Sign up to request clarification or add additional context in comments.

8 Comments

Thank you, the form is not sent. I don't know why. A conflict with jQuery validate form plugin ?
@Xroad - not a jQuery issue, at least not yet. It is your Mail Transfer Agent issue. What configuration have you done to your SMTP server? What tests have you made to confirm the new configuration is working?
Well I use Wamp for testing my PHP processing page. And I use Fake Sendmail to send mail locally. I checked the file "error.log" in sendmail and I see : "14/04/01 14:00:29 : Connection Closed Gracefully." Wamp gives me no errors. But with the script of aSeptik I got "Form not sent" at the end.
in "PHP.ini" I put sendmail_path = "C:\wamp\sendmail\sendmail.exe -t"
Wow, it seems to be hard to test a simple function :-( In the "sendmail.ini" I put : smtp_server=smtp.gmail.com ; smtp_port=25 ; auth_username= my gmail mail adress ; auth_password= my password
|
1

i think you have problem with your host, so we try to use gmail SMTP server to send emails.

in order to do so, i'm going to use an email library called Swift, download it free here http://swiftmailer.org/ once you downloaded it just rename the folder into swift and setup the $smtp_settings username and password (the one you use to login into your gmail account) and be sure that the required file

require_once dirname(__FILE__).'/swift/lib/swift_required.php';

is in the right path. (as it is now you can simply have the swift folder in the same root of the mail file)

<?php
function send_mail($to, $from, $subject='', $body='', $smtp=array()){

    // be sure this point where the swift package is...
    require_once dirname(__FILE__).'/swift/lib/swift_required.php';

    $settings = (object)$smtp;

    $transport = Swift_SmtpTransport::newInstance($settings->host, $settings->port, $settings->encryption)
    ->setUsername($settings->username)
    ->setPassword($settings->password);

    $mailer = Swift_Mailer::newInstance($transport);

    $_from = is_array($from) ? $from : array($from);

    $_to = is_array($to) ? $to : array($to);

    $message = Swift_Message::newInstance($subject)
    ->setFrom($_from)
    ->setTo($_to)
    ->setBody($body);

    $result = $mailer->send($message);

    return $result;
}

if(isset($_POST) && isset($_POST['form_firstname']) && isset($_POST['form_name']) && isset($_POST['form_email']) && isset($_POST['form_telephone']) && isset($_POST['form_message'])) {
    extract($_POST);
    if(!empty($form_firstname) && !empty($form_name) && !empty($form_email) && !empty($form_telephone) && !empty($form_message)) {

        // SMTP Server Configuration
        $smtp_settings = array(
            'host' => 'smtp.gmail.com',
            'port' => 465,
            'encryption' => 'ssl',
            'username' => '[email protected]',
            'password' => '************',
            );

        // Send an email to client and a copy to us...
        $to = '[email protected]'; // who receive

        $from = array('[email protected]' => 'My Site Name'); // who send

        $subject = 'Contact from the site';

        //$message = stripslashes($form_message)."\r\n"; 
        $message  = 'A question came'."\r\n"; 
        $message .= 'Firstname : '.$form_firstname."\r\n"; 
        $message .= 'Name : '.$form_name."\r\n"; 
        $message .= 'Email : '.$form_email."\r\n"; 
        $message .= 'Message : '.$form_message."\r\n";

        if(send_mail($to, $from, $subject, $message, $smtp_settings)){
            echo "Email sent";
        } else {
            echo "Email not sent";
        }

    } else {
        echo "You have not filled in the field";
    }
}
?>

7 Comments

Thank you for your code, that run well, and finally I have "Form not sent" that appears at the end. So I got a problem somewhere. Probably a conflict with jQuery validate form plugin ?
@Xroad: the problem is with your host (remote or local). so try to send it via gmail SMTP server like in my updated code...
Ok I tried and I have errors in my PHP file 1 {main}( ) ..\traitement.php:0 2 send_mail( ) ..\traitement.php:55 3 Swift_Mailer->send( ) ..\traitement.php:24
Ok I changed from Gmail to Free for SMTP and it's run, than you ! But I have a little problem. If I type "Test" in message, I receive : "TestA question came" of if I type "Hello" I got : "HelloA question came". Other question can I have other thing to protect the form data that I will receive ?
just add ."\r\n"; see the code... for the other question not sure what you mean? protect from spambot?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.