-1

I've created a HTML form with inputs named 'name' , 'email' , 'mobile' , 'message'.

Within my HTML i have used;

<form action='form_script.php' method='post'>

which will (when submitted) send to my form_script.php where my PHP should execute.

form_script.php

I have then created this php script which is supposed to get the the inputs from the form and send an email to 'enquiries@firelineband.co.uk'.

The problem is, the email is not being sent. I've checked through my PHP script numerous times and i can't seem to find any problem, which is why i have resulted in posted on here to have a second opinion.

if(isset($_POST['submit'])){
$to = "enquiries@firelineband"; // this is your Email address
$from = $_POST['email']; // this is the sender's Email address
$name = $_POST['name'];
$mobile = $_POST['mobile']; 
$subject = $_POST['subject'];
$subject2 = "Copy of your form submission";
$message = "Name: " .$name . "\n\n mobile number: " . $mobile . ".\n\n Message:" . "\n\n" . $_POST['message'];
$message2 = "Here is a copy of your message " . $name . "\n\n" . $_POST['message'];

$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
// You can also use header('Location: thank_you.php'); to redirect to another page.
}

Thanks in advance for your time. Sam

HTML Form

<table style='width:100%'> 
            <form action='form_script.php' method='post'>
            <tr> 
                <th> <input type='text' required placeholder='Name' name='name' /> </th> <th> <input type='text' required placeholder='Email' name='email' /> </th> 
            </tr> 

            <tr> 
                <th> <input type='text' required placeholder='Mobile' name='mobile' /> </th> <th> <input type='text' required placeholder='Subject' name='subject'  /> </th> 
            </tr>
            <tr> 
                <th colspan='2'><textarea required placeholder='Message' name='message' ></textarea></th> 
            </tr>
            <tr> 
                <th><input id='send_form' type='submit' /> </th>
            </tr>
            </form>
        </table> 
methhead
  • 115
  • 2
  • 12

3 Answers3

0

If you are trying send email on localhost, you should set settings for email in php.ini depend on your ISP.

It is for my country(Croatia) isp name(T-Com):

ini_set("SMTP", "mail.t-com.hr");
ini_set("smtp_port", "25");

$message = "";

if(mail('aaaa@gmail.com', 'title', $message, "From: bbbb@gmail.com"))
{
    echo 'sent succesfull';
}

but it depends on isp and country.

PS.ini_set "("SMTP", "mail.t-com.hr");" and "ini_set("smtp_port", "25");" can be called from code or set in php.ini

fico7489
  • 7,931
  • 7
  • 55
  • 89
0

Why use the standard vanilla php mail function() . rather switch to Mailgun or phpmailer which you can autoload into your code and send mails that way. its alot faster and more reliable then mail() function. and with using mailgun for example; you can see a log via there website and see if your mails have sent 100% or not. Good luck

0

You do not have any input which have name='submit'. Add this in your form

<input type="hidden" name="submit">.

Since your code says if(isset($_POST['submit'])) but $_POST['submit'] is not set.

Crunch Much
  • 1,537
  • 1
  • 11
  • 14