PHP Mailer Code Mailing Blank

Im having trouble Im new to PHP but Im familiar with Classic ASP which is very similar minus a few $ signs etc.

I have this PHP mailer code and for some reason it is mailing but its mailing blank. I have tried to keep the sendmail.php short until is working so Im not sending all fields until I know it works for less errors simplicity FYI

I have included entire pages code so that maybe I have overlooked something.

Can someone please help me fix this code so it sends the data in the email. I have tried avery aspect I can find in the last 4 hours and IM at a lost on it.

Thanks in advance.

Contact Form:

Contact-us.html

[php]

Contact Us | Affordable Fence Guys
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/bootstrap-responsive.min.css">
<link rel="stylesheet" href="css/font-awesome.min.css">
<link rel="stylesheet" href="css/main.css">
<link rel="stylesheet" href="css/sl-slide.css">

<script src="js/vendor/modernizr-2.6.2-respond-1.1.0.min.js"></script>

<!-- Le fav and touch icons -->
<link rel="shortcut icon" href="images/ico/favicon.ico">
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="images/ico/apple-touch-icon-144-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="images/ico/apple-touch-icon-114-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="images/ico/apple-touch-icon-72-precomposed.png">
<link rel="apple-touch-icon-precomposed" href="images/ico/apple-touch-icon-57-precomposed.png">
<!--Header-->
<header class="navbar navbar-fixed-top">
    <div class="navbar-inner">
        <div class="container">
            <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </a>
            <a id="logo" class="pull-left" href="index.html"></a>
            <div class="nav-collapse collapse pull-right">
                <ul class="nav">
                    <li><a href="index.html">Home</a></li>
                    <li><a href="about-us.html">About Us</a></li>
                    <li><a href="services.html">Services</a></li>
                    <li><a href="portfolio.html">Portfolio</a></li>
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">Pages <i class="icon-angle-down"></i></a>
                        <ul class="dropdown-menu">
                            <li><a href="career.html">Career</a></li>
                            <li><a href="blog-item.html">Blog Single</a></li>
                            <li><a href="faq.html">FAQ</a></li>
                            <li><a href="pricing.html">Pricing</a></li>
                            <li><a href="404.html">404</a></li>
                            <li><a href="typography.html">Typography</a></li>
                            <li><a href="registration.html">Registration</a></li>
                            <li class="divider"></li>
                            <li><a href="privacy.html">Privacy Policy</a></li>
                            <li><a href="terms.html">Terms of Use</a></li>
                        </ul>
                    </li>
                    <li><a href="blog.html">Blog</a></li> 
                    <li class="active"><a href="contact-us.html">Contact</a></li>
                    <li class="login">
                        <a data-toggle="modal" href="#loginForm"><i class="icon-lock"></i></a>
                    </li>
                </ul>        
            </div><!--/.nav-collapse -->
        </div>
    </div>
</header>
<!-- /header -->

<section id="contact-page" class="container">
    <div class="row-fluid">

        <div class="span8">
            <h4>Contact Form</h4>
            <div class="status alert alert-success" style="display: none"></div>

            <form id="main-contact-form" class="contact-form" name="contact-form" method="post" action="sendemail.php">
              <div class="row-fluid">
                <div class="span5">
                    <label>First Name</label>
                    <input type="text" class="input-block-level" required="required" placeholder="Your First Name">
                    <label>Last Name</label>
                    <input type="text" class="input-block-level" required="required" placeholder="Your Last Name">
                    <label>Phone</label>
                    <input type="text" class="input-block-level" required="required" placeholder="Your Phone Number">
                    <label>Email Address</label>
                    <input type="text" class="input-block-level" required="required" placeholder="Your Email Address">
                </div>
				<div class="span6">
                    <label>Address</label>
                    <input type="text" class="input-block-level" required="required" placeholder="Your Address">
                    <label>City</label>
                    <input type="text" class="input-block-level" required="required" placeholder="Your City">
                    <label>State</label>
                    <input type="text" class="input-block-level" required="required" placeholder="Your State">
                    <label>Zip</label>
                    <input type="text" class="input-block-level" required="required" placeholder="Your Zip">

                </div>
                <div class="span7">
                    <label>Message</label>
                    <textarea name="message" id="message" required="required" class="input-block-level" rows="8"></textarea>
                </div>

            </div>
            <button type="submit" class="btn btn-primary btn-large pull-right">Send Message</button>
            <p> </p>

        </form>
    </div>
</section>
    <!--row-fluids-->
    <div class="row-fluid">

        <!--Contact Form-->
        <div class="span3">
            <h4>Affordable Fence Guys Phone Nubmer</h4>
            <ul class="unstyled address">
                <li>
                    <i class="icon-phone"></i>
                    <strong>Contact Us Today For a Free Estimate:</strong> 803-374-7373
                </li>
            </ul>
        </div>
        <!--End Contact Form-->
    </div>

</div>
<!--/row-fluid-->
© 2004 Affordable Fence Guys. All Rights Reserved.
        <div class="span6">
            <ul class="social pull-right">
                <li><a href="https://www.facebook.com/affordablefenceguys/"><i class="icon-facebook"></i></a></li>
            </ul>
        </div>

        <div class="span1">
            <a id="gototop" class="gototop pull-right" href="#"><i class="icon-angle-up"></i></a>
        </div>
        <!--/Goto Top-->
    </div>
</div>

Login Form

Remember me Sign in Forgot your password?

[/php]

Sendmail.php

[php]

<?php header('Content-type: application/json'); $status = array( 'type'=>'success', 'message'=>'Email sent!' ); $fname = @trim(stripslashes($_POST['First name'])); $email = @trim(stripslashes($_POST['email'])); $message = @trim(stripslashes($_POST['message'])); $email_from = $email; $email_to = '[email protected]'; $body = 'Name: ' . $fname . "\n\n" . 'Email: ' . $email . "\n\n" . 'Message: ' . $message; $success = @mail($email_to, $body, 'From: <'.$email_from.'>'); echo json_encode($status); die; [/php]

I suggest you use PHPMailer instead of the included mail function - which doesn’t give you any feedback except a bool to say if it was successful or not.

[hr]

I also strongly recommend you don’t suppress errors (prefixing method calls with @), you want your app to handle errors - not just ignore them.

It all looks good but you just way blew my mind… I just went into overload on how to even process that to implement. May be out of my league quite yet. A simple Form and Mailer file is easier for me to work with. That appears to have about 100 different files I would never be able to configure that properly at my knowledge level today.

Any easier PHPMailers?

Being as I can’t see if you are submitting the form via JavaScript, I will assume you are using the submit button behavior.

Since you are not serializing the form, that I can tell, everyone of your inputs is missing a name attribute. Which would explain why no entered information is being passed by $_POST to the page that sends the form.

PHP isn’t actually complicated to implement. You just download it and use their crash course to help you with the code to get up and going quickly.

Don’t be intimidated by the number of files. If you’re not into Composer (package manager) etc yet, just download the PHPMailer files, and unzip it into your project dir.

Use this code for sendmail (though smtp is better):
[php]<?php
/**

  • This example shows sending a message using a local sendmail binary.
    */
    require ‘…/PHPMailerAutoload.php’;
    //Create a new PHPMailer instance
    $mail = new PHPMailer;
    // Set PHPMailer to use the sendmail transport
    $mail->isSendmail();
    //Set who the message is to be sent from
    $mail->setFrom(‘[email protected]’, ‘First Last’);
    //Set an alternative reply-to address
    $mail->addReplyTo(‘[email protected]’, ‘First Last’);
    //Set who the message is to be sent to
    $mail->addAddress(‘[email protected]’, ‘John Doe’);
    //Set the subject line
    $mail->Subject = ‘PHPMailer sendmail test’;
    //Read an HTML message body from an external file, convert referenced images to embedded,
    //convert HTML into a basic plain-text alternative body
    $mail->msgHTML(file_get_contents(‘contents.html’), dirname(FILE));
    //Replace the plain text body with one created manually
    $mail->AltBody = ‘This is a plain-text message body’;
    //Attach an image file
    $mail->addAttachment(‘images/phpmailer_mini.png’);
    //send the message, check for errors
    if (!$mail->send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
    } else {
    echo “Message sent!”;
    }[/php]
    https://github.com/PHPMailer/PHPMailer/blob/master/examples/sendmail.phps

Remember to change this to the location to PHPMailer
[php]require ‘…/PHPMailerAutoload.php’;[/php]

probably
[php]require ‘./PHPMailer/PHPMailerAutoload.php’;[/php]

And of course change the rest of the code to reflect your email, name, wanted data, etc.

That’s it :slight_smile:

Well I didnt even notice that was missing… Valid point Im sure names would help. I think I have crashed it completely now Im getting nothing… I had hair at 45 lol I may not have any in the next hour lol… Im going to rest my sendmail.php to scratch minimums and restructure again from all your notes. Until I can maybe find an easier solution I can logically work with. I have some working classic asp but I dont want to use it as Im trying to stay strictly .html files this go round.

This is a full website restructure to make Responsive as my last was html5 but not Responsive for Android or IPhone. Laptop, Desktop, Tablet and Ipad was fine but phones didnt like it.

Apparently Im not pushing anything to the sendmail.php

I have to be missing a piece on the contact-us.php

This is what its returning in email…

Name:

Email:

Subject:

Message:

if you get a blank page that’s usually a server error. You should show all errors in your development environment, which you can do by adding this to the top of your php file(s)

[php]error_reporting(E_ALL);
ini_set(‘display_errors’, 1);[/php]

That would likely be because there are no name attributes, or they are named differently.

Add
print_r($_POST);
To the page that should send the mail.

I have fixed my error but Im unsure how… LOL Go figure dumb luck and some playing around.

I will research why after I pickup my daughter from school and post how when I figure it out…

Here is what I returned in my email after the reset and a few adjustments like field names name=“email” etc and I made a reset to the form but Im unsure what I may have errored before.

Thank You all for your help and encouragement

Name: Kurt

Email: [email protected]

Subject:

Message: My Email2

Also, never suppress your error messages. So, remove the “@” from all of your functions. That “@” is used to
hide errors from being displayed. It is not helpful in your code.

Sponsor our Newsletter | Privacy Policy | Terms of Service