1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

php mail() form problem

Discussion in 'PHP & Perl' started by monchichi, Jun 7, 2012.

  1. monchichi

    monchichi Power Member

    Joined:
    Jun 3, 2011
    Messages:
    591
    Likes Received:
    248
    Occupation:
    BOSS.
    Location:
    173.194.35.147
    hey guys,

    why this code doesnt send any mail ?

    Code:
    <?php
    
    if(!$_POST) exit;
    
    $email = $_POST['express_field2'];
    $error = '';
    $errors = 0;
    
    //$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS';
    if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){
        $error.="Invalid email address entered" . "\n";
        $errors=1;
    }
         
        $your_email = "mailadress@mailhost.com";
        $email_subject = "New Message:";
        $email_content = "New Message:\n\n";
        $header = "from: Ydesign";
        
        if(!empty($_POST['express_field1']) && $_POST['express_field1'] != 'Ihre Website *'){
            $email_content .= 'Ihre Website: ' . " => ". $_POST['express_field1']."\n";
        } else {
            $error.="Please Fill in Ihre Website" ."\n";
            $errors=1;
        }
        
        $email_content .= 'Ihre E-Mail-Adresse: ' . " => ". $_POST['express_field2']."\n";
        
        $email_content .= 'für folgende Leistung:' . " => ". $_POST['express_options']."\n";
        
        if(!empty($_POST['express_field3']) && $_POST['express_field3'] != 'Ihr Name *'){
            $email_content .= 'Ihr Name' . " => ". $_POST['express_field3']."\n";
        } else{
            $error.="Please Fill in Ihr Name" . "\n";
            $errors=1;
        }
        $email_content .= 'Firma: ' . " => ". $_POST['express_field4']."\n";
        
        if(!empty($_POST['express_field5']) && $_POST['express_field5'] != 'Telefonnummer *'){
            $email_content .= 'Telefonnummer: ' . " => ". $_POST['express_field5']."\n";
        } else{
            $error.="Please Fill in Telefonnummer" . "\n";
            $errors=1;
        }
        $email_content .= 'Ihre Nachricht an uns: ' . " => ". $_POST['express_field6']."\n";
        
        
        if(isset($_POST['express_suchbegriff_1'])){
            $email_content .= 'Ihre wichtigsten Suchbegriffe 1: ' . $_POST['express_suchbegriff_1']."\n";
        }
        if(isset($_POST['express_suchbegriff_2'])){
            $email_content .= 'Ihre wichtigsten Suchbegriffe 2: ' . $_POST['express_suchbegriff_2']."\n";
        }
        if(isset($_POST['express_suchbegriff_3'])){
            $email_content .= 'Ihre wichtigsten Suchbegriffe 3: ' . $_POST['express_suchbegriff_3']."\n";
        }
        if(isset($_POST['express_suchbegriff_4'])){
            $email_content .= 'Ihre wichtigsten Suchbegriffe 4: ' . $_POST['express_suchbegriff_4']."\n";
        }
        if(isset($_POST['express_suchbegriff_5'])){
            $email_content .= 'Ihre wichtigsten Suchbegriffe 5: ' . $_POST['express_suchbegriff_5']."\n";
        }
        if(isset($_POST['express_suchbegriff_6'])){
            $email_content .= 'Ihre wichtigsten Suchbegriffe 6: ' . $_POST['express_suchbegriff_6']."\n";
        }
        if(isset($_POST['express_suchbegriff_7'])){
            $email_content .= 'Ihre wichtigsten Suchbegriffe 7: ' . $_POST['express_suchbegriff_7']."\n";
        }
        
        
        if($errors == 1){
            echo $error;
        } else if(@mail($your_email,$email_subject,$email_content, $header)) {
            echo 'Message sent!'; 
        } else {
            echo 'ERROR!';
        }
    
    ?>
     
  2. monchichi

    monchichi Power Member

    Joined:
    Jun 3, 2011
    Messages:
    591
    Likes Received:
    248
    Occupation:
    BOSS.
    Location:
    173.194.35.147
    any php expert in here who can fix the form for me ?
    will pay for help.
     
  3. OriginalEXE

    OriginalEXE Power Member

    Joined:
    Feb 6, 2012
    Messages:
    634
    Likes Received:
    664
    Occupation:
    WordPress developer
    Home Page:
    What do you get when you try submitting form?
     
  4. monchichi

    monchichi Power Member

    Joined:
    Jun 3, 2011
    Messages:
    591
    Likes Received:
    248
    Occupation:
    BOSS.
    Location:
    173.194.35.147
    "Message sent" but actually not sending
     
  5. OriginalEXE

    OriginalEXE Power Member

    Joined:
    Feb 6, 2012
    Messages:
    634
    Likes Received:
    664
    Occupation:
    WordPress developer
    Home Page:
    Well why are you trying to send an email to
    mailadress@mailhost.com ?

    $your_email should be the email of the receiver, To:, I believe your email is not
    mailadress@mailhost.com ?
     
  6. monchichi

    monchichi Power Member

    Joined:
    Jun 3, 2011
    Messages:
    591
    Likes Received:
    248
    Occupation:
    BOSS.
    Location:
    173.194.35.147
    I simply edited the email adress so I dont post my email adress in here... of course the code has my correct email.
     
  7. OriginalEXE

    OriginalEXE Power Member

    Joined:
    Feb 6, 2012
    Messages:
    634
    Likes Received:
    664
    Occupation:
    WordPress developer
    Home Page:
    Oh :)

    Try removing @ from the front of the mail function and then sending the mail.
     
  8. monchichi

    monchichi Power Member

    Joined:
    Jun 3, 2011
    Messages:
    591
    Likes Received:
    248
    Occupation:
    BOSS.
    Location:
    173.194.35.147
    didnt help aswell.

    I tried:

    remove @
    using wordpress wp_mail() instead of mail()
    same issue, always giving "message sent" but no email sent
     
  9. monchichi

    monchichi Power Member

    Joined:
    Jun 3, 2011
    Messages:
    591
    Likes Received:
    248
    Occupation:
    BOSS.
    Location:
    173.194.35.147
    Form is actually based on two files

    one with the form and the other the one above with the sending function.

    ANY PHP EXPERT LIKES TO FIX THIS FOR ME FOR A PAYMENT ?
     
  10. OriginalEXE

    OriginalEXE Power Member

    Joined:
    Feb 6, 2012
    Messages:
    634
    Likes Received:
    664
    Occupation:
    WordPress developer
    Home Page:
    Ok, try changing if(!eregi... line with this one:

    PHP:
    if(!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/",$email)){
     
  11. monchichi

    monchichi Power Member

    Joined:
    Jun 3, 2011
    Messages:
    591
    Likes Received:
    248
    Occupation:
    BOSS.
    Location:
    173.194.35.147
    nothing, same as before
     
  12. OriginalEXE

    OriginalEXE Power Member

    Joined:
    Feb 6, 2012
    Messages:
    634
    Likes Received:
    664
    Occupation:
    WordPress developer
    Home Page:
    Then something must be wrong with your hosting server.
     
  13. monchichi

    monchichi Power Member

    Joined:
    Jun 3, 2011
    Messages:
    591
    Likes Received:
    248
    Occupation:
    BOSS.
    Location:
    173.194.35.147
    I installed wp plugin "advanced email options" to test if its working.
    and it is working, when I click send testmail it always comes through. using mail() funktion and using wp_mail() function.
    so no hosting issue.
     
  14. MacFly

    MacFly Newbie

    Joined:
    Dec 7, 2011
    Messages:
    43
    Likes Received:
    41
    Location:
    /root
    Did you check your antispam filter ? Perhaps the mail is sent but blocked...
     
  15. monchichi

    monchichi Power Member

    Joined:
    Jun 3, 2011
    Messages:
    591
    Likes Received:
    248
    Occupation:
    BOSS.
    Location:
    173.194.35.147
    no spam filter issue as well. simply not sending email.

    I am simply looking for someone now who will fix that for me :(
    i dont care if the form will be sent via mail() wp_mail() or anything else. I just need my form to be sent via email..
     
  16. MacFly

    MacFly Newbie

    Joined:
    Dec 7, 2011
    Messages:
    43
    Likes Received:
    41
    Location:
    /root
    Did you try mail($your_email,$email_subject,$email_content, $header) alone to see if it works ?
     
  17. monchichi

    monchichi Power Member

    Joined:
    Jun 3, 2011
    Messages:
    591
    Likes Received:
    248
    Occupation:
    BOSS.
    Location:
    173.194.35.147
    yes, that works
     
  18. skrode

    skrode Junior Member

    Joined:
    Nov 13, 2011
    Messages:
    103
    Likes Received:
    16
    I had similar problem few days ago, but "Configure SMTP" plugin for Wordpress fixed it.
     
  19. monchichi

    monchichi Power Member

    Joined:
    Jun 3, 2011
    Messages:
    591
    Likes Received:
    248
    Occupation:
    BOSS.
    Location:
    173.194.35.147
    its not a sending problem. error has to be in the code I posted.
     
  20. skrode

    skrode Junior Member

    Joined:
    Nov 13, 2011
    Messages:
    103
    Likes Received:
    16
    was the from header "Ydesign" when you tested the mail function alone? sometimes valid email is required
     
    Last edited: Jun 7, 2012