-1

I am having to sort out my companies contact form. It seems to not work when you click on the submit button: My company website is : www.f-sharpmedia.com.

Here is the code for my PHP File:

 <?php
 $name = $_POST['name'];
 $email = $_POST['email'];
 $message = $_POST['message'];
 $from = 'From: F-Sharp Media'; 
 $to = 'f.ajibade@f-sharpmedia.com'; 
 $subject = 'Hello';

 $body = "From: $name\n E-Mail: $email\n Message:\n $message";

 mail( "f.ajibade@f-sharpmedia.com" , "New Project" , $body);
 header("Location:email_success.php");
 ?>

EMAIL_SUCESS PHP FILE:

 <!doctype html>
 <html class="no-js" lang="en">
 <head>
    <meta charset="utf-8" />
    <title>F-Sharp Media | Welcome</title>
    <link rel="stylesheet" href="css/foundation.css" />
    <link rel="stylesheet" href="css/main.css" />
    <script src="js/vendor/modernizr.js"></script>
   </head>

     <body>
    <h1> Email Sent</h1>
    <p>Your e-mail has been sent<p/>
    <p><a href="JavaScript:history.go(-1);">Back</a></p>
     </body>
    </html>

Contact Form HTML :

        <form action="server.php" method="post">

                <p>
                <label for="name">Name:</label>
                <input name="name" id="name" type="text" class="required">
                <span>Please enter your name</span>
                </p>

                <p>
                <label for="email">Email:</label>
                <input name="email" id="email" type="text" class="required"> 
                <span>Please enter a valid email address</span>
                </p>

                <p>
                <label for="subject">Subject:</label>
                <input name="subject" id="subject" type="text"> 
                <span>Please enter your subject</span>
                </p>

                <p>
                <label for="message">Message</label>
                <textarea name="message" id="message" class="required"></textarea> 
                <span>Please enter your message</span>
            </p>
            <p class="submit">
                <input type="submit" value="Submit" class="btn-submit">
            </p>
        </form>
Rahid
  • 17
  • 9
  • 2
    If you want help, you need to tell us what is not working. Does the email never arrive in your inbox? Does an error show up on the page? – conradkleinespel Aug 14 '14 at 12:07
  • Try checking the return value of the `mail()` call which will tell you if it is queueing the email or not. – Anigel Aug 14 '14 at 12:08
  • `if(mail(....)){...}else{ // error code }` > [**error reporting**](http://php.net/manual/en/function.error-reporting.php) – Funk Forty Niner Aug 14 '14 at 12:09
  • I assume mail server settings have been set up correctly as well – n34_panda Aug 14 '14 at 12:10
  • The email doesnt arrive in my inbox. Is this something to do with my host provider or is my mail function not in the correct format. @conradk – Rahid Aug 14 '14 at 12:12
  • Am sure the mail function return value is the email you want it to send to along with other information e.g header , message, name etc @Anigel – Rahid Aug 14 '14 at 12:13
  • That's strange Rahid as it should just return true or false. You may want to check the docs http://php.net/manual/en/function.mail.php – Anigel Aug 14 '14 at 12:25

2 Answers2

0

The mail() function returns true or false depending on whether the mail was sent or not (which does not mean it will reach the inbox because it might be considered spam). More information here: http://php.net/manual/de/function.mail.php

I recommend you apply the suggestion from Fred to see if your message was accepted by your email provider. Something like:

if(mail(....)) {
    echo 'ok';
} else {
    echo 'error';
}
exit();

If error appears on the page, it means your email was rejected. There is not much you can do with your current script to change that. Below are some suggestions.

You seem to be using Google Apps. Google has an aggressive spam fighting policy. Your email will probably never reach your inbox with such a simplistic script. If you care about deliverability, you may want to look into Swiftmailer or services such as Postmark or Sendgrid.

conradkleinespel
  • 6,560
  • 10
  • 51
  • 87
0

Try to change 'From: ' label from $body variable, some server retrieve it like header and don't send the email.

$body = "Who: $name\n E-Mail: $email\n Message:\n $message";

Enjoy your code!

Magicianred
  • 566
  • 2
  • 8