0

Having an issue being able to send mail using PHP I have looked through my code and can't find where I'm going wrong. Edited with my html instered.

<?php
if (isset($_POST['primaryemail'])){
    $first_name = $_POST['first_name'];
    $phone_number = $_POST['phone_number'];
    $phone_numbertwo = $_POST['phone_numbertwo'];
    $primaryemail = $_POST['primaryemail'];


    if (!empty($primaryemail)) {
        $to = 'testemail@gaming.com';
        $subject = 'Jobsite Form Submitted';
        $body = "Submitted by: " . $first_name . "Phone number: " . $phone_number . "Secondary phone number: " . $phone_numbertwo;
        $headers = 'From:' . $primaryemail;
        mail($to, $subject, $body, $headers);   
    }
}
?>

<form name="jobsiteform" class="jobsiteform" method="POST" action="">
<h2>Contact Information</h2>
<h4>Primary Contact Information</h4>
<br>
    <label>Full Name: &nbsp;</label>
    <input type="text" name="first_name" id="first_name" maxlength="70" placeholder="First & Last" required>
    <br><br>
    <label>Phone Number: &nbsp;</label>
    <input type="text" name="phone_number" id="phone_number" class="phone" maxlength="13" placeholder="(xxx) xxx-xxxx" required>
    <br><br>
    <label>Secondary Phone Number: &nbsp;</label>
    <input type="text" name="phone_numbertwo" id="phone_numbertwo" class="phone" maxlength="13" placeholder="Optional">
    <br><br>
    <label>E-mail: &nbsp;</label>
    <input type="email" name="email" maxlength="100" id="primaryemail" placeholder="e.g. first.last@domain.com" required>
    <br>

James
  • 65
  • 1
  • 10

2 Answers2

3

Use name="" not id='' in your HTML

You need to modify your html you have the ID set to what the Name should be on your primary email field. The name parameter is used by the Post request to PHP not ID (often used by javascript).

<input type="email" name="primaryemail" maxlength="100" id="primaryemail" placeholder="e.g. first.last@domain.com" required>

Therefore your php script never executes due to this line beacuse the post value is set to the key $_POST['email'] not $_POST['primaryemail'] therefore it is not set.

if (isset($_POST['primaryemail'])){

That is why it is a good idea to do an else at the end of that and echo 'error: post email not sent';

Patrick Murphy
  • 2,311
  • 14
  • 17
1

Put your PHP code in an extern file, add the path to that file in your action="path to file" and add a submit button inside <form>. Example: <input type="submit" value="Send">.

Gustaf Gunér
  • 2,272
  • 4
  • 17
  • 23