-2

I have not working this code.i want to send mail to the email id but it woudnt happened, I have not working this code.i want to send mail to the email id but it woudnt happened , I have not working this code.i want to send mail to the email id but it woudnt happened ,code as below:-

         <h2>Your Contact Info</h2>
          <p>Your First Name* <br />
            <input type="text" name="firstName" id="firstName" required />
          </p>
          <p>Your Last Name* <br />
            <input type="text" name="lastName" id="lastName" required />
          </p>
          <p>Your Email* <br />
            <input type="email" name="email" id="email" required />
          </p>
          <p>Upload Your logo<br />
            <input type="file" name="uploaded_file" id="uploaded_file"> 
          </p>
          <input type="submit" name="submit" />
         </form>

    <?php
    if(isset($_POST['submit'])) {
     $emailAddress = 'xyz@gmail.com';
     $mail=$_POST['email'];
     require_once('php/_lib/class.phpmailer.php');
    $msg = 'First Name:'.$_POST['firstName'].'<br /> Last name:'.$_POST['lastName'].'<br /> Email:'.$_POST['email'].'<br />';
    move_uploaded_file($_FILES["uploaded_file"]["tmp_name"], $_FILES["uploaded_file"]["name"]);
      $mail = new PHPMailer();
      $mail->IsMail();
      $mail->AddReplyTo($mail);
      $mail->AddAddress($emailAddress);
      $mail->From($mail);
      $mail->Subject = "Subject";
      $mail->MsgHTML($msg);
      $mail->AddAttachment( $_FILES["uploaded_file"]["name"]);
      $mail->Send();

        enter code here

      echo'<script> window.location="../index.html"; </script> ';
    }
      ?>
  • 1
    check the php mailer docs for the correct usage of `AddAttachment()` because i am pretty sure you did not use it right – Rotimi Dec 12 '17 at 08:23
  • 1
    Please refer the below thread of Stackoverflow for your answer: https://stackoverflow.com/questions/12301358/send-attachments-with-php-mail – Prabhat Kasera Dec 12 '17 at 08:24
  • 1
    you really need to improve on how you explain your problems though. The message body of your question makes no sense – Rotimi Dec 12 '17 at 08:25

1 Answers1

1

Initially $mail is an email address then it becomes a PHPMailer object then the AddReplyTo is set to be PHPMailer Object ( That's not very strange!!! ).

So for starters change

$mail=$_POST['email'];

To

$reply_to_email=$_POST['email'];

And then change...

$mail->AddReplyTo($mail);

To

$mail->AddReplyTo($reply_to_email);

And you need to validate that $_POST['email'] is an email address and not someones shopping list etc... You are open to attack with that form.

Whoops I missed more misuse of $mail...

$mail->From($mail);

Should be, or rather, not be the above...

$mail->From($respond_to_email);

Change the names to suit, but do not call them $mail!

UPDATE: In Addressing your "stated issue" and without regurgitating the answer here, go and read up on how to use $mail->AddAttachment Here

Community
  • 1
  • 1
TimBrownlaw
  • 5,457
  • 3
  • 24
  • 28