0

I am trying to create a 'contact me' form by sending data in HTML form to an email address using php mail() function.

I am using xampp and testing my code on localhost. I have installed Test Mail Server Tool and it is running on port 25.

Configuration of php.ini file

[mail function]
; XAMPP: Comment out this if you want to work with an SMTP Server like Mercury

; SMTP = smtp.secureserver.net

; smtp_port = 25

; For Win32 only.

; http://php.net/sendmail-from

;sendmail_from = zain.farid@live.com

HTML Code

<form action="upload.php" method="post" style="height:100%">

                <input name="articleTitle" value="Title" maxlength="50" 
                id="articleTitle">

                <textarea name="article-body">
                    Compose your article...
                </textarea>

            <script>
                CKEDITOR.inline( 'article-body' );
            </script>


                <input name="senderName" type="text" value="Name" maxlength="50" 
                id="name" class="textBox">

                <input name="senderEmail" value="Email address" maxlength="50" 
                id="email" class="textBox">

                <input name="abtyou" value="About Yourself" maxlength="150" 
                id="abtyou" class="textBox">

                <input type="submit" name="submit" class="button">

            </form>

PHP Code

<?php

    $thankYou="";   

if(isset($_POST["submit"])) {
    $recipient="zain.farid@live.com";
    $subject="New Guest Post";
    $sender=$_POST["senderName"];
    $senderEmail=$_POST["senderEmail"];
    $senderAbout=$_POST["abtyou"];
    $message=$_POST["article-body"];
    $title=$_POST["articleTitle"];

    $mailBody="Name: $sender\nEmail: $senderEmail\nAbout Sender: $senderAbout\nTitle: $title\n\n$message";

    mail($recipient, $subject, $mailBody, "From: $sender <$senderEmail>");

    $thankYou="Thank you! Your post has been submitted.";
}

?>

No error is reported but i cant see any email in my inbox of the mentioned email address. Can you please spot the error. I think its a configuration problem because i am using mail server for the first time and i think i might have made an error in configuration. Thank you

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
zaain
  • 13
  • 6
  • 1
    the semicolon is a comment character. remove the semicolon in front of your required settings – Jonathan Gray Dec 13 '14 at 21:33
  • Also, if you've installed the Test Mail Server Tool, I'd expect (a) your SMTP server to be localhost, and (b) for mail not to be actually sent. That's why it's a *Test* Mail Server Tool. – Matt Gibson Dec 13 '14 at 21:35
  • @MattGibson Thank you. I changed the server to localhost and removed the semicolon from both server and port. What email address should i use for $recipient if want to send a mail to local server? – zaain Dec 13 '14 at 21:41
  • The Test Mail Server Tool accepts any email sent to port 25, no matter what the address, and shows it to you so you know your mail configuration is working. The address doesn't matter. – Matt Gibson Dec 13 '14 at 21:53
  • You need to remove the `;` for the options you need to be used. Just as this says *"Comment out this if you want to work with an SMTP Server like Mercury"* – Funk Forty Niner Dec 13 '14 at 22:13

1 Answers1

-1

first check your spam box and do notice that main mail services for preventing from spam and fake email reject this type of email ,for test , I think you should set valid mail server accounts like google yahoo and ...

Ashouri
  • 906
  • 4
  • 19