Results 1 to 5 of 5

Thread: php mail form with confirmation not sending mail

  1. #1
    Join Date
    Jul 2006
    Location
    Antwerp, Belgium (Europe)
    Posts
    902
    Thanks
    114
    Thanked 2 Times in 2 Posts

    Default php mail form with confirmation not sending mail

    Hey all,

    This is the php I have for my mail form with confirmation:

    Code:
    <?php
    if ($_POST["action"] == "send"){
    if ($_POST[name] != "" and $_POST[email] != "" and $_POST[message] != "") { 
    
    mail ("MYMAILADRESS", "contact via LenG", 
    
    "
    Naam: ".$_POST['name']."
    
    E-mail: ".$_POST['email']."
    
    Bericht: ".$_POST['message']."
    ",
    
    "From: ".$_POST['name']." <".$_POST['email'].">");
    $headers[] = 'LenG';
    $subject = "bevestiging mail LenG"; 
    $msg = "
    
    (Dit is een automatisch verzonden bericht. Gelieve hierop niet te antwoorden.)
    
    Beste $_POST[name],
    
    Dankje voor je interesse.
    Binnen de twee werkdagen mag je een antwoord verwachten.
    
    Voor dringende vragen, bel gerust.
    
    Graag tot binnenkort,
    Bruno
    
    ";  
    
    mail($_POST[email], $msg, implode("\r\n", $headers)); 
    echo '<br><div style="background-color:#fff;border:2px solid #f91942;padding:20px;color:#393939;margin-bottom:50px;margin-top:-20px;width:100%;text-align:center;"><p>Dankje voor je interesse. Binnen de twee werkdagen mag je een antwoord verwachten.</p></div>';
    }
    else{
    echo '<br><div style="background-color:#f91942;border:2px solid #fff;padding:20px;margin-bottom:50px;margin-top:-20px;width:100%;text-align:center;color:#fff;"><p>Vul alle velden in, aub. Dankje.</p></div>';
    }
    }
    ?>

    And this is the html:

    Code:
    <form method="post" id="contactForm" action="#contact">
    					<input type="hidden" name="action" value="send">
    					<div class="row">
    						<div class="col-md-6">
    							<div class="form-group">
    								<input type="text" id="name" name="name" placeholder="je naam">
    							</div>
    						</div>
    						<div class="col-md-6">
    							<div class="form-group">
    								<input type="email" id="email" name="email" placeholder="je email adres">
    							</div>
    						</div>
    					</div>
    					<div>
    						<textarea id="comments" name="message" placeholder="je bericht"></textarea>
    					</div>
    				<input type="submit" class="submit button" id="send" value="verzend">
    				</form>
    For some reason the mail form seems to send the mail (the error or sent message comes up), but it doesn't arrive. No problem with my mailbox, but something in the php doesn't handle it correctly.
    Any advice, please?

  2. #2
    Join Date
    Jan 2015
    Posts
    77
    Thanks
    0
    Thanked 18 Times in 18 Posts

    Default

    The first mail() statement is using a header parameter that says the email is being sent from the email address that was entered in the form. Except during testing, where you might be entering your own email address at your web hosting, these emails are NOT being sent from the email address that someone entered in the form. They are being sent from a mail server at your web hosting and the From: mail header must correspond to your web hosting, and all the DNS zone records at your web hosting must be setup so that the mail server matches your domain and is authorized to send email for your domain. You can check the DNS records and basic email functionality at dnsstuff.com

    The second mail() statement is missing a subject parameter, so, the other parameters past that point are in the wrong location, and the header parameter apparently consists of just a string, not a valid From: mail header, unless you altered what you posted, in which case you should just xxxxx out information, not alter the meaning of what you are posting.

    For both the mail() statements, if the sending mail server returns an error to php, the mail() statement will return a false value to the php code. Your code should test this value and only output a success message if a true value is returned. A true value doesn't necessary mean that the email will get sent or accepted by the receiving mail server, it just means that the sending mail server has accepted the email. If the mail call fails, php will use it's error_reporting, display_errors, and log_errors settings to control what happens with the actual error information. The error_reporting setting should always be set to E_ALL. When debugging a problem like this, you can set display_errors to ON, so that you will get any errors output to the browser. When on a live/public web site, you should instead log all errors. By adding logic to test the value being returned from the mail() call, you can at least determine if the sending mail server is accepting the email.

  3. #3
    Join Date
    Jul 2006
    Location
    Antwerp, Belgium (Europe)
    Posts
    902
    Thanks
    114
    Thanked 2 Times in 2 Posts

    Default

    Thanks for your explanation, DyDr.
    But this is the form I've used so far for ages, and all works well.
    Now I'm just trying to incorporate it into another form design, but it doesn't work anymore (deleted the subject input):

    Code:
    <?php
    if ($_POST["action"] == "send"){
    if ($_POST[name] != "" and $_POST[email] != "" and $_POST[subject] != "" and $_POST[message] != "") { 
    
    mail ("MY@EMAILADRESS.COM", "contact via website", 
    
    "
    Name: ".$_POST['name']."
    
    E-mail: ".$_POST['email']."
    
    Subject: ".$_POST['subject']."
    
    Thoughts: ".$_POST['message']."
    ",
    
    "From: ".$_POST['name']." <".$_POST['email'].">");
    $headers[] = 'From: MYDOMAIN.COM';
    $subject = "confirmation mail"; 
    $msg = "
    
    (This is an automatically sent message. Please do not reply.)
    
    Dear $_POST[name],
    
    Thanks for your interest.
    
    Surely I will get back to you within a short delay.
    In case you need fast response, please do not hesitate calling me.
    Thanks.
    
    Enjoy your day.
    
    Kind regards,
    B
    
    ";  
    
    mail($_POST[email], $subject, $msg, implode("\r\n", $headers)); 
    echo '<br><div style="background-color:#fff;border:2px solid #e61875;padding:20px;color:#393939;margin:auto;width:80%;text-align:center;"><p>Thanks for your thoughts. A confirmation mail is on its way and I will get back to you within a short delay.<br>In case you need fast response, please do not hesitate calling me.</p></div>';
    }
    else{
    echo '<br><div style="background-color:#e61875;border:2px solid #fff;padding:20px;margin:auto;width:80%;text-align:center;color:#fff;"><p>Your thoughts could not be shared. Please try again filling in all fields.<br>Thanks.</p></div>';
    }
    }
    ?>
    
    					<hr class="spacer">
    					<form method="post" id="contactForm" action="#contact">
    						<input type="hidden" name="action" value="send">
    						<div class="row">
    							<div class="col-lg-5 col-lg-offset-1">
    								<div class="form-group">
    									<input type="text" class="form-control input-lg" id="name" name="name" placeholder="your euphonious name">
    								</div>
    							</div>
    							<div class="col-lg-5">
    								<div class="form-group">
    									<input type="email" class="form-control input-lg" id="email" name="email" placeholder="your email adress">
    								</div>
    							</div>
    							<div class="col-lg-10 col-lg-offset-1">
    								<div class="form-group">
    									<input type="text" class="form-control input-lg" id="subject" name="subject" placeholder="your most loyal subject">
    								</div>
    							</div>
    							<div class="col-lg-10 col-lg-offset-1">
    								<div class="form-group">
    									<textarea class="form-control" rows="6" id="message" name="message" placeholder="&nbsp;&nbsp;&nbsp;please share your thoughts"></textarea>
    								</div>
    							</div>
    							<div class="col-lg-10 col-lg-offset-1">
    								<div class="form-group text-right">
    									<button type="submit" class="btn btn-primary btn-lg" id="send"><i class="arrow_carrot-right_alt2"></i>send</button>
    								</div>
    							</div>
    						</div>
    					</form>

  4. #4
    Join Date
    Jul 2006
    Location
    Antwerp, Belgium (Europe)
    Posts
    902
    Thanks
    114
    Thanked 2 Times in 2 Posts

    Default

    So, in other words:

    How can this code:
    Code:
    <?php
    if ($_POST["action"] == "send"){
    if ($_POST[name] != "" and $_POST[email] != "" and $_POST[subject] != "" and $_POST[message] != "") { 
    
    mail ("MY@EMAILADRESS.COM", "contact via website", 
    
    "
    Name: ".$_POST['name']."
    
    E-mail: ".$_POST['email']."
    
    Subject: ".$_POST['subject']."
    
    Thoughts: ".$_POST['message']."
    ",
    
    "From: ".$_POST['name']." <".$_POST['email'].">");
    $headers[] = 'From: MYDOMAIN.COM';
    $subject = "confirmation mail"; 
    $msg = "
    
    (This is an automatically sent message. Please do not reply.)
    
    Dear $_POST[name],
    
    Thanks for your interest.
    
    Surely I will get back to you within a short delay.
    In case you need fast response, please do not hesitate calling me.
    Thanks.
    
    Enjoy your day.
    
    Kind regards,
    B
    
    ";  
    
    mail($_POST[email], $subject, $msg, implode("\r\n", $headers)); 
    echo '<br><div style="background-color:#fff;border:2px solid #e61875;padding:20px;color:#393939;margin:auto;width:80%;text-align:center;"><p>Thanks for your thoughts. A confirmation mail is on its way and I will get back to you within a short delay.<br>In case you need fast response, please do not hesitate calling me.</p></div>';
    }
    else{
    echo '<br><div style="background-color:#e61875;border:2px solid #fff;padding:20px;margin:auto;width:80%;text-align:center;color:#fff;"><p>Your thoughts could not be shared. Please try again filling in all fields.<br>Thanks.</p></div>';
    }
    }
    ?>
    be implemented in this html form:
    Code:
    <form method="post" id="contactForm" action="#contact">
    					<input type="hidden" name="action" value="send">
    					<div class="row">
    						<div class="col-md-6">
    							<div class="form-group">
    								<input type="text" id="name" name="name" placeholder="je naam">
    							</div>
    						</div>
    						<div class="col-md-6">
    							<div class="form-group">
    								<input type="email" id="email" name="email" placeholder="je email adres">
    							</div>
    						</div>
    					</div>
    					<div>
    						<textarea id="comments" name="message" placeholder="je bericht"></textarea>
    					</div>
    				<input type="submit" class="submit button" id="send" value="verzend">
    				</form>

  5. #5
    Join Date
    Feb 2018
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hii,

    If you send mail using PHP mailing script, you have to give all entry in proper way. there are some of entry missing.
    Last edited by jscheuer1; 02-02-2018 at 02:36 PM. Reason: excessive quoting

Similar Threads

  1. Replies: 1
    Last Post: 06-26-2015, 12:16 PM
  2. Simple PHP E-mail Confirmation
    By Abbster22 in forum PHP
    Replies: 0
    Last Post: 08-10-2010, 03:14 PM
  3. Resolved Auto mail sending
    By hassan in forum PHP
    Replies: 0
    Last Post: 10-11-2008, 09:04 AM
  4. sending e-mail via hotmail
    By lelu in forum PHP
    Replies: 1
    Last Post: 03-20-2007, 01:47 PM
  5. Background sending of php mail
    By titanite in forum PHP
    Replies: 3
    Last Post: 02-27-2006, 05:04 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •