使用php表单发送和重新发送电子邮件

时间:2017-04-26 00:16:24

标签: php aptana

我正在尝试检索发件人的电子邮件,发件人姓名,邮件主题和发送的邮件。 您还将在代码中看到我想使用empty()函数检查发件人的姓名,电子邮件地址和邮件是否为空。如果其中一个为空,我想在文档中显示错误消息。否则,请调用send_email()函数。

现在我的输出显示了部分代码。我需要格式化方面的帮助,或者我错过了一步。

<?php

    require_once ('c:/wamp64/www/Lab6/PHPMailerAutoload.php');

    function sendEmail($fromEmail,$fromName,$subject, $message){

        $mailer = new PHPMailer;
        $mailer->isSMTP();

        $mailer->Host = 'smtp.gmail.com';
        $mailer->Port = 587;

        $mailer->SMTPSecure = 'tls';
        $mailer->SMTPAuth = true;

        $mailer->Username= "geogumd@gmail.com";
        $mailer->Password= "gis@umd2016";

        $mailer->From= $fromEmail;
        $mailer->FromName=$fromName . "(" . $fromEmail . ")";

        $mail->IsHTML(true);

        $mailer->Subject=$subject;      
        $mailer->Body=$message;

        $mailer->addAddress('worthem.aleah@terpmail.umd.edu', 'Aleah');
        $mailer->Sendmail($fromEmail,$fromName,$subject,$message);

        if(!$mailer->send()) {
        $h = "Mailer Error " . $mailer->ErrorInfo;
        $m = "Mailer Error was not sent";
        print "<h1>$h</h1>";
        print "<pre>$m</pre>";
    }else{          
        print "<h1>Mail Sent</h1>";
        print "<p>Thank you. Your message has been sent successfully.</p>";
    }
    }
?>

<div id="content">
    <?php

    $user_input1 = $_POST['From'];
    $user_input2 = $_POST['FromName'];
    $user_input3 = $_POST['Subject'];
    $user_input4 = $_POST['Body'];

    if(!empty($user_input1) && is_string($user_input1)&&
    (!empty($user_input2) && is_string($user_input2))&&
    (!empty($user_input3) && is_string($user_input3))&& 
    (!empty($user_input4) && is_string($user_input4))
    )
        {
            sendEmail($user_input1, $user_input2, $user_input3, $user_input4);          
        }
    else{
            print "<h4>Sorry</h4>";
            print "<p>You didnt fill out the form completley. <a href='index.php?action=sendmail'>Try Again";
        }

    ?>

0 个答案:

没有答案