Send email using phpMailer





PHP Content



    <?php
    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
        require 'phpmailer/PHPMailerAutoload.php';
        $name = $_POST['namecontact']; 
        $email = $_POST['emailcontact'];
        $number = $_POST['numbercontact'];
        $msg = $_POST['messagecontact'];
        $mail = new PHPMailer();
        $mail->IsSMTP();
        $mail->SMTPOptions = array(
            'ssl' => array(
                'verify_peer' => false,
                'verify_peer_name' => false,
                'allow_self_signed' => true,
            ),

        );
        $mail->Host = "smtp.gmail.com"// host name
        $mail->SMTPAuth = true;
        $mail->SMTPSecure = "ssl"// ssl or tls
        $mail->Port = 465// port number
        $mail->Username = "testmail@gmail.com";
        $mail->Password = "emailidpassword";
        $mail->From = "testmail@gmail.com";
        $mail->FromName = "From name";
        $recipients = array(

            'sendtoemailid@gmail.com' => 'Person One',

        );
        foreach ($recipients as $email1 => $name1) {
            $mail->AddBCC($email1$name1);
        }
        //Set the subject line
        $mail->Subject = 'write here email subject';
        // email body text and design
        $mail->msgHTML('<html><body><table border=0 width=554><tr><td colspan=2><p><b>Enquiry from  company name contact us Page</b><br><br></p></td></tr><tr><td colspan=2 class=text4>FORM     submitted at ' . date('d F Y h:i:s A') . '<br></td></tr><tr><td width=200 class=text3>Name  :</td><td class=text3>' . $name . '</td></tr><tr><td>Email Id :</td><td>' . $email . '</ td></tr><tr><td>Phone Number :</td><td>' . $number . '</td></tr><tr><td>Message:</td><td>'   . $msg . '</td></tr></table></body></html>');

        if (!$mail->send()) {

            //write code here if email not sent  

            echo '<script>alert("Something is wrong please try again from server");</script>';

        } else {
            // write code here if email has been sent
        }

    }

    ?>


Comments

Post a Comment