skip to Main Content

I am having an issue while sending email query to multiple emails account in php, can anybody help here is the form HTML version

<form id="contact-form" action="#">
    <div class="form-field-item">
        <input type="text" required="required" name="fullname" id="fullname" size="25" placeholder="Name" class="form-field">
    </div>
    <div class="form-field-item">
        <input type="tel" id="phone" name="phone" required="required" placeholder="Contact Number" class="form-field">
    </div>
    <div class="form-field-item">
        <input type="email" required="required" name="email" id="email" placeholder="Email" class="form-field">
    </div>
    <div class="form-field-checkbox-item">
        <div class="checkbox-item">
            <input type="checkbox" id="agree-gdrp" name="agree-gdrp" required="required" value="Yes">
            <label for="agree-gdrp" class="field-label">I agree that Fraser handles my personal data in accordance with GDPR</label>
        </div>
    </div>
    <div class="form-submit-wrap">
        <button>Send Enquiry</button>
    </div>
</form>

… and here is the PHP:

<?php 
$recepient = "[email protected],[email protected]"; 
$sitename = "Fraser"; 
$fullname = trim($_POST["fullname"]); 
$email = trim($_POST["email"]); 
$phone = trim($_POST["phone"]); 
$message = "Name: $fullname nContact Number: $phone nEmail: $email"; 
$pagetitle = "Fraser Contact Form"; 

mail($recepient, $pagetitle, $message, "Content-type: text/plain; charset="utf-8"n From: [email protected]");
?>

3

Answers


  1. More and more hosters are going to block the sending of mails send to multiple recipents using the mail() function since you can provide any “From” address which may be blocked by the recipents due to SPF checks.
    You may build up a whole SMTP connection to send your mail, maybe by using a Lib like the SwiftMailer.

    Login or Signup to reply.
  2. Try this

    $email_to  = "[email protected],[email protected]"; 
    $sitename = "Fraser"; 
    $fullname = trim($_POST["fullname"]); 
    $email = trim($_POST["email"]); 
    $phone = trim($_POST["phone"]); 
    $message = "Name: $fullname nContact Number: $phone nEmail: $email"; 
    $pagetitle = "Fraser Contact Form"; 
    
    mail($email_to , $pagetitle, $message);
    

    it will work if your host doesnt block, if does! then you will need to use smtp like gmail or other providers.

    Alternate you can use PHPMailer

    Login or Signup to reply.
  3. How are you sending the data to be processed by php. i have added a script to the form action and replaced your submit button with an input of type submit

    HTML

    <form id="contact-form" action="my_processing_script.php">
        <div class="form-field-item">
            <input type="text" required="required" name="fullname" id="fullname" size="25" placeholder="Name" class="form-field">
        </div>
        <div class="form-field-item">
            <input type="tel" id="phone" name="phone" required="required" placeholder="Contact Number" class="form-field">
        </div>
        <div class="form-field-item">
            <input type="email" required="required" name="email" id="email" placeholder="Email" class="form-field">
        </div>
        <div class="form-field-checkbox-item">
            <div class="checkbox-item">
                <input type="checkbox" id="agree-gdrp" name="agree-gdrp" required="required" value="Yes">
                <label for="agree-gdrp" class="field-label">I agree that Fraser handles my personal data in accordance with GDPR</label>
            </div>
        </div>
        <div class="form-submit-wrap">
            <input type='submit' value='Send Enquiry'>
        </div>
    </form>
    

    my_processing_script.php

    <?php 
    $recepient = "[email protected],[email protected]"; 
    $sitename = "Fraser"; 
    $fullname = trim($_POST["fullname"]); 
    $email = trim($_POST["email"]); 
    $phone = trim($_POST["phone"]); 
    $message = "Name: $fullname nContact Number: $phone nEmail: $email"; 
    $pagetitle = "Fraser Contact Form"; 
    
    mail($recepient, $pagetitle, $message, "Content-type: text/plain; charset="utf-8"n From: [email protected]");
    ?>
    

    If you dont want to leave the page i would suggest posting the form via ajax or jquery post

    <button id="my-submit-button">Send Enquiry</button>
    

    JQuery

    $("#my-submit-button").click(function(e){
        var fullname = $("#fullname ").val()
        var phone = $("#phone ").val()
        var email = $("#email ").val()
        var agree_gdrp = $("#agree-gdrp").val()
        $.post("my_php_sctipt.php", {"fullname" :fullname, "phone":phone, "email" : email , "agree_gdrp": agree_gdrp }).done(function(evt){
            alert("data sent");
        })
    })
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search