-2

I am pretty new to all this and I need some help. This is the most basic mail function in PHP.

  <?php
    $headers = "Content-Type: text/html; charset=UTF-8";
    $name=$_POST['name'];
    $email=$_POST['email'];
    $subject=$_POST['subject'];
    $phone=$_POST['phone'];
    $message=$_POST['message'];
    $to ="maria@mkitra.com";
    $subject2 = "Work";
    mail($to, $subject2, $message, $headers, $name);
    echo "Message Sent";

    ?>

It does send the email but my problem is that the mail function doesn't include either the user's email nor their phone number. How do I include them in the email?

I have tried

mail($to, $subject2, $message, $headers,$phone,$email $name);

But it says, the mail function can take maximum 5 parameters. I am confused.

  • are you trying this code on local server? – Hamza Zafeer Jul 11 '16 at 15:36
  • 3
    Did you look at the manual? Parameter 1 to, parameter 2 subject, parameter 3 message, parameter 4 headers. http://php.net/manual/en/function.mail.php Everything you want in the body of the email goes in `$message`. – chris85 Jul 11 '16 at 15:37
  • You cannot use mail() because in most cases for security reasons (spammer scripts or just holes in code that send mail without providing credentials) it's not configured. Solution: create mail account, use https://github.com/PHPMailer/PHPMailer and send using example. – num8er Jul 11 '16 at 15:37
  • Did you try Google? i'm sure there tons of answers to this question including stackoverflaw – E_p Jul 11 '16 at 15:38
  • What do you mean "_include them in the email_"? Do you mean in the body of the email? or in the subject of the email? – Mr. Meeseeks Jul 11 '16 at 15:41
  • For a hideous looking email try `mail($to, $subject2, $message . $phone . $email . $name, $headers);` – chris85 Jul 11 '16 at 15:41

1 Answers1

3

You can use this

<?php
        $to = $_POST['email'];      //Whom you want to send                  
        $from = "maria@mkitra.com"; //Your email id
        $subject = $_POST['subject'];
        $message = '<!DOCTYPE html><html><head><meta charset="UTF-8"><title>yoursitename Message</title></head><body><span>Mobile</span><span>'.$phone.'</span><span>Name‌​</span><span>'.$name.'</span></body></html>';
        $headers = "From: $from\n";
        $headers .= "MIME-Version: 1.0\n";
        $headers .= "Content-type: text/html; charset=iso-8859-1\n";
        mail($to, $subject, $message, $headers);
        echo "Message Sent";

Email only send to and email subject and email body and email type mean header. No send mobile number or name or any other things. If you add this then you add on your under email body

chris85
  • 23,846
  • 7
  • 34
  • 51
Suman
  • 401
  • 5
  • 15
  • Answers should include a description of what you changed and why. This doesn't include the additional information the OP is needing. `doesn't include the user's email nor their phone number,so I can't reply, how do I include them in the email` The OP is trying to email himself then reply to the sender, based on what was sent (as I read it). – chris85 Jul 11 '16 at 15:46
  • You can use html tag on message body and use echo phone number and all other things – Suman Jul 11 '16 at 15:48
  • Echoing won't put the content in the email.. – chris85 Jul 11 '16 at 15:50
  • 1
    I add example `$message = ' yoursitename MessageMobile'.$phone.'Name'.$name.'';` – Suman Jul 11 '16 at 15:55
  • I edit them and explain how doing that. – Suman Jul 11 '16 at 16:00