Click here to Skip to main content
15,920,633 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Dear all,
I have a problem with my PHP mail sending. I am a beginner with PHP.
I get this result and my email does not send:

PHP
Strict Standards: Non-static method Mail::factory() should not be called statically in C:\xampp\htdocs\phptest\email.php on line 34

Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:\xampp\php\PEAR\Mail\smtp.php on line 365

Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:\xampp\php\PEAR\Net\SMTP.php on line 450

Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:\xampp\php\PEAR\Net\SMTP.php on line 467


This is configuration of my PHP at Php.ini:
PHP
[mail function]
SMTP = smtp.gmail.com
smtp_port = 465
mail.add_x_header = Off


and this is my code at email.php:
PHP
<form method="post">
Gmail username: <input type="text" name="MailFrom"/><br />
Gmail password: <input type="text" name="MailPass"/><br />
Send Email To: <input type="text" name="MailTo"/><br />
Subject: <input type="text" name="MailSubject"/><br />
<!--CC: <input type="text" name="MailCC"/><br />-->
Body: <input type="text" name="MailBody"/><br />
<input type="Submit" name="submitMail" value="Submit Mail"/>
</form>

if(!empty($_POST['submitMail']))
{
    require_once "mail.php";

    $MailFrom=$_POST['MailFrom'];
    $MailPass=$_POST['MailPass'];
    $MailTo=$_POST['MailTo'];
    $MailSubject=$_POST['MailSubject'];
    //$MailCC=$_POST['MailCC'];
    $MailBody=$_POST['MailBody'];

    $MailHost = "smtp.gmail.com";
    $MailPort = "465";

    $headers = array ('From' => $MailFrom,
                      'To' => $MailTo,
                      'Subject' => $MailSubject);
    $smtp = Mail::factory('smtp',
                   array ('host' => $MailHost,
                          'port' => $MailPort,
                          'auth' => true,
                          'username' => $MailFrom,
                          'password' => $MailPass));

    $mail = $smtp->send($MailTo, $headers, $MailBody);

    if (PEAR::isError($mail))
    {
        echo("<p>" . $mail->getMessage() . "</p>");
    }
    else
    {
        echo("<p>Message successfully sent!</p>");
    }

}

?>
Posted

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900