-2

My code is :

<?php
            if(isset($_POST['submit'])){


                //veryfing the name
                if(empty($_POST['name'])){ ?>
                    <div class="alert alert-danger alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>PLease enter your name .</div>
                <?php}
                else{
                    $name = htmlentities($_POST['name']);
                }


                //veryfing the email
                if(empty($_POST['email'])) { ?>
                    <div class="alert alert-danger alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>PLease enter your email .</div>
                <?php}
                else if(filter_var($_POST['email'] , FILTER_VALIDATE_EMAIL === false)){ ?>
                    <div class="alert alert-danger alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>PLease enter a valid email .</div>
                <?php }
                else{
                    $email ="<". htmlentities($_POST['email']).">";
                }



                if(empty($_POST['message'])){?>
                    <div class="alert alert-danger alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>PLease enter some message .</div>
                <?php}
                else{
                    $message = htmlentities($_POST['message']);
                }
                if(empty($_POST['name'] ) or empty( $_POST['email']) or empty($_POST['message']) ){?>
                    <div class="alert alert-danger alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>Something went wrong ! .</div>
                <?php}
                else{
                    $headers = 'From: {$email}' . "\r\n" .
                        'Reply-To: {$email}' . "\r\n" .
                        'X-Mailer: PHP/' . phpversion();
                    $send_mail = mail("seiramami12@gmail.com" , "An email from Omarmannan.net" , $message , $headers);

                }
                if(!$send_mail){?>
                    <div class="alert alert-danger alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>Something went wrong ! .</div>
                <?php }
                else{
                    echo '<div class="alert alert-success">Email successfully sent. Thank you for your message.</div>';
                }
            }?>

But i can not send mail . I have been working with my own personal website . In my contact page I can not send mail with this code . After clicking the submit button it shows a blank page .

1 Answers1

0

php mail() function behave unexpected in sometime.

In my experience -- and others' -- the mail() function is not particularly predictable, or >helpful.

Quite notably, the mail() function behaves entirely differently between Linux and Windows >servers. On linux it uses sendmail, but on Windows it uses SMTP.

In order for the mail() function to even work at all php.ini needs to be configured >correctly, specifying the location of sendmail or of an SMTP server.

The problem with mail() is that it "tries" to simplify things to the point that it actually >makes things more complex due to poor interface design. The developers of Swift Mailer have >gone to a lot of effort to make the Mail Transport work with a reasonable degree of >consistency.

i suggest you that use SwiftMailer library For Send Mail, That Is Very Strong.

Community
  • 1
  • 1
ghanbari
  • 1,630
  • 1
  • 16
  • 31