-1

I need someone to guide me on how to properly use Mail () function in php.

I wanted to make a simple form where users can send me their Name and e-mail so that I can send them invitation.

I wanted to code it using mail () function in php.

Note : I'm not intending to create a contact form but a form with just two field ; Just Name and e-mail.

Hope someone can help.

Adetona
  • 27
  • 1
  • 6
  • first result in google: http://www.123contactform.com/simple-php-contact-form.html?disablecdn=yes (PHP Basic Contact Form) – Akam Mar 15 '16 at 08:58

2 Answers2

0

Here is the sample code as per your requirement

<?php 
$action=$_REQUEST['action']; 
if ($action=="")    /* display the contact form */ 
{ 
?> 
    <form  action="" method="POST" enctype="multipart/form-data"> 
    <input type="hidden" name="action" value="submit"> 
    Your name:<br> 
    <input name="name" type="text" value="" size="30"/><br> 
    Your email:<br> 
    <input name="email" type="text" value="" size="30"/><br> 
    Your message:<br> 
    <textarea name="message" rows="7" cols="30"></textarea><br> 
    <input type="submit" value="Send email"/> 
    </form> 
    <?php 
    }  
else                /* send the submitted data */ 
    { 
    $name=$_REQUEST['name']; 
    $email=$_REQUEST['email']; 
    $message=$_REQUEST['message']; 
    if (($name=="")||($email=="")||($message=="")) 
        { 
        echo "All fields are required, please fill <a href=\"\">the form</a> again."; 
        } 
    else{         
        $from="From: $name<$email>\r\nReturn-path: $email"; 
        $subject="Message sent using your contact form"; 
        mail("youremail@yoursite.com", $subject, $message, $from); 
        echo "Email sent!"; 
        } 
    }   
?> 

Hope this helps

Jobins John
  • 1,265
  • 23
  • 45
0

You can try This way.

$to_mail="ex@domain.com";
        $subject="subject";
        $message = "you can put in it your Form Data";// like name and Email that you want to send
        // a random hash will be necessary to send mixed content
        $separator = md5(time());
        // carriage return type (we use a PHP end of line constant)
        $eol = PHP_EOL;
        // main header (multipart mandatory)
        $headers = "MIME-Version: 1.0" . $eol;
        $headers .= "Content-Type: multipart/mixed; boundary=\"" . $separator . "\"" . $eol . $eol;
        $headers .= "Content-Transfer-Encoding: 7bit" . $eol;
        $headers .= "This is a MIME encoded message." . $eol . $eol;
        $headers .= "--" . $separator . $eol;
        $headers .= "Content-Type: text/html; charset=\"iso-8859-1\"" . $eol;
        $headers .= $message . $eol . $eol;
        @mail("$to_mail","$subject","",$headers);
Apon Ahmed
  • 53
  • 1
  • 9