-1

On my previous post, I was asking regarding email with attachment. It's the first time for me to do one. And to make it simple, I have no idea how to do it. I have done some tutorials and such but it doesn't seem to work.

I have a contact page working, I will write down the information below. It is working but I need to add an attachment

here is the link

http://jsfiddle.net/misaki03/e7mwn93u/

<?php

$to = "prettychii03@gmail.com";
$subject = isset($_POST['subject']) ? $_POST['subject'] : '';

$fname = isset($_POST['fname']) ? $_POST['fname'] : '';
$lname = isset($_POST['lname']) ? $_POST['lname'] : '';
$email = isset($_POST['email']) ? $_POST['email'] : '';
$pnum = isset($_POST['pnum']) ? $_POST['pnum'] : '';
$message = isset($_POST['message']) ? $_POST['message'] : '';
$emailType = isset($_POST['emailType']) ? $_POST['emailType'] : '';

$body = <<<Email

First Name: $fname
Last Name: $lname
Email Address: $email
Phone Number: $pnum
Message:
$message

Thanks,
$lname, $fname

Email;
$header = "From: $email";

$subject2 = $emailType." : ".$subject;
if($_POST){
    if($lname == '' || $fname == '' || $email == '' || $pnum == '' || $message == ''){

    }else{
        mail($to, $subject2, $body, $header);
        echo "Thank you for sending us an email! We have recieved your message.";
    }

}
?>

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>My title</title>
<link href="style2.css" rel="stylesheet" />

</head>
<body>
<div id="container"> <!--wrapper-->
    <header id="header">
        <div id="menu" class="menu"> <!--navMenu-->
            <ul>
                <li><a href="index.php" > HOME </a></li>
                <li>OUR PRODUCT
                <ul> 
                    <li><a href="productOverview.php" > PRODUCT OVERVIEW</a></li>
                    <li><a href="usage.php" > CHEESECLOTH USAGE</a></li>
                    <li><a href="reviews.php" > PRODUCT REVIEWS </a></li>
                </ul>
                </li>
                <li> SUGGESTIONS 
                <ul>
                    <li><a href="tips.php" > TIPS and IDEAS </a></li>
                    <li><a href="recipe.php" > RECIPES </a></li>
                    <li><a href="ideas.php" > SEND US YOUR IDEAS </a></li>
                </ul>
                </li>
                <li><a href="about.php" > ABOUT US </a> </li>
                <li><a href="contact.php" > CONTACT US </a> </li>
            </ul> 
            <br class="clearFloat" />
        </div>
</header>

<section id="content">
        <div class="about" id="about">
        <center>
            <h2>- CONTACT US -</h2>
            <h4>Got any question or comments for us? Or do you have any suggestion that you would want us to share the world? Give us your thoughts and we might feature your work on our site! Don't hesitate to send us an email using the form below.
            <br /><br />
            <div id="contactUs">
            <form action="?" method="post">
                <table style="width:750px; border:0">
                    <tr>
                        <td><label for="fname">First Name : </label> </td>
                        <td><input type="text" name="fname" id="fname" required="required" /> </td>
                    </tr>
                    <tr>
                        <td><label for="lname">Last Name : </label></td>
                        <td><input type="text" name="lname" id="lname" required="required" /></td>
                    </tr>
                    <tr>
                        <td><label for="email">Email : </label></td>
                        <td><input type="text" name="email" id="email" required="required" /></td>
                    </tr>
                    <tr>
                        <td><label for="pnum"> Phone Number : </label></td>
                        <td><input type="text" name="pnum" id="pnum" required="required" /></td>
                    </tr>
                    <tr>
                        <td><label for="emailType">Email Type : </label></td>
                        <td>
                            <select name="emailType" required="required">
                                <option value="Comments">Comments</option>
                                <option value="Question">Question</option>
                                <option value="Recipe Suggestion">Recipe Suggestion</option>
                                <option value="Tips Suggestion">Tips Suggestion</option>
                                <option value="Other">Other</option>

                            </select>
                        </td>

                    </tr>
                    <tr>
                        <td><label for="subject">Subject : </label></td>
                        <td><input type="text" name="subject" id="subject" required="required" /></td>
                    </tr>
                    <tr>
                        <td><label for="message">Message : </label></td>
                        <td><textarea id="message" name="message" cols="42" rows="9" required="required"></textarea></td>
                    </tr>
                    <tr>
                        <td colspan="2"><div class="buttonSubmit" id="buttonSubmit">
                                <input type="submit" value="Submit">
                        </div></td>
                    </tr>
                </table>
            </form>
                <h3>Jungle Sales LLC / <br />
                    7495 W. Azure Dr. Suite 110<br />
                    Las Vegas, NV 89130</h3>
            </div>
        </center>
        </div>

</section>

<footer id="footer">
    <div id="fmenu" class="fmenu">
        <p>©2015 copyright    |  All Rights Reserved</p>
        <ul class="social_icons">
            <li class="social">
                <a href="#" target="_blank">
                    <img src="images/fb.png" /> </a></li>
            <li class="social">
                <a href="#" target="_blank">
                    <img src="images/pin.png" /> </a></li>
            <li class="social">
                <a href="#" target="_blank">
                    <img src="images/insta.png" /> </a></li>
        </ul>
</footer>
    </div>

</div>
</body>
</html>

I have been told to use PHPMailer, how do I add that in my code. one comment here mentioned require code. but not sure what else should I add since it is a different code from what I learned. Sorry and thanks for the help.

MisaChan
  • 279
  • 1
  • 5
  • 15
  • Is that condition is fine?? $_FILES[['attachment']['name']] => $_FILES['attachment']['name'] – Vishu238 Oct 17 '15 at 13:23
  • Please try to reduce your question to just what is needed to describe the problem. I doubt that CSS has anything to do with your problem, neither does a jsfiddle, because its for JavaScript not PHP ;-)... Read here for more infos: http://stackoverflow.com/help/how-to-ask – toesslab Oct 17 '15 at 14:05
  • it's really hard to explain. to keep things simple. I don't know how to make contact us page with attachment. i tried different tutorials but it doesn't seem to work – MisaChan Oct 20 '15 at 06:41
  • I have already clarified my question @mario. sorry if it was confusing or seemed like a duplicate. – MisaChan Oct 21 '15 at 03:00

1 Answers1

0

You should consider to use: https://github.com/PHPMailer/PHPMailer

it is far more simple to send email with attachment with this plugin.

My example:

<?php

require 'PHPMailer/PHPMailerAutoload.php';
$email = new PHPMailer();
$email->From      = $email_from;
$email->FromName  = $name;
$email->Subject   = $subject;
$email->Body      = $body;

$email->AddReplyTo($email_from, $name);
$email->AddAddress( $receiver );

if(isset($_FILES['fileAttach'])){
    $name_file = $_FILES['fileAttach']['name'];
    $path_file  = $_FILES['fileAttach']['tmp_name'];

    $email->AddAttachment( $path_file ,$name_file );
}
$flgSend = $email->Send();
if($flgSend){
    //success
}else{
    //error
}
fico7489
  • 7,931
  • 7
  • 55
  • 89
  • i tried this and got confused. could you teach me how to use this @fico7489 ? – MisaChan Oct 20 '15 at 06:38
  • look at my edited answer . – fico7489 Oct 20 '15 at 06:47
  • oh, so i just need to add require. this is the current working code I have (without attachment) do I simply add those codes above? (link here - http://jsfiddle.net/misaki03/e7mwn93u/ – MisaChan Oct 21 '15 at 02:54
  • i have tried what you said. I adjusted it based on what I needed. it's working fine on my wamp server however, once I uploaded it on the domain, its giving me this error "Server error 500. It may be down for maintenance or configured incorrectly." here is the code i used. http://jsfiddle.net/misaki03/e7mwn93u/2/ – MisaChan Oct 22 '15 at 04:17