Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Mail

PHP code to send an email

the mail() function

Moderators: macek, egami, gesf

PHP code to send an email

Postby eramesh » Thu Aug 18, 2011 6:03 am

Hi,
I am new to php and i am trying to send an email from php code. But unfortunately i am getting some errors. Please see my below code.....

<?php
require_once "Mail.php";

$from = "ramesh sender<ramemsc@yahoo.com";
$to = "ramesh Recipient <eramesh.msc@gmail.com>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";

$host = "ssl://mail.yahoo.com";
$port = "25";
$username = "e.rameshbabu";
$password = "xxxx";

$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password));

$mail = $smtp->send($to, $headers, $body);

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

Please see the errors i am getting here .....


Deprecated: Assigning the return value of new by reference is deprecated in C:\xampp\php\PEAR\Mail.php on line 154

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

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 225

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

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 339

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

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

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

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

Strict Standards: Non-static method PEAR::isError() should not be called statically in C:\xampp\htdocs\sendemail.php on line 26

Failed to connect to ssl://mail.yahoo.com:25 [SMTP: Failed to connect socket: Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP? (code: -1, response: )]

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 364

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 196

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

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

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


I would be great if anyone helps me in this case.... I will be waiting for your response.......


Thank you very much,
Ramesh
eramesh
New php-forum User
New php-forum User
 
Posts: 2
Joined: Mon Aug 15, 2011 12:49 am

Re: PHP code to send an email

Postby bigjoe11a » Tue Sep 27, 2011 1:36 pm

well I don't know why your using the mail function like that and since I have no knowledge on that. This is better. Just use the PHP mail function.

Code: Select all
// Mine

<?
    //change this to your email.
    $to = "m@maaking.com";
    $from = "m2@maaking.com";
    $subject = "Hello! This is HTML email";

    //begin of HTML message
    $message = "<html>
  <body bgcolor=\"#DCEEFC\">
    <center>
        <b>Looool!!! I am reciving HTML email......</b> <br>
        <font color=\"red\">Thanks Mohammed!</font> <br>
        <a href=\"http://www.maaking.com/\">* maaking.com</a>
    </center>
      <br><br>*** Now you Can send HTML Email <br> Regards<br>MOhammed Ahmed - Palestine
  </body>
</html>";
   //end of message

    // To send the HTML mail we need to set the Content-type header.
    $headers = "MIME-Version: 1.0rn";
    $headers .= "Content-type: text/html; charset=iso-8859-1rn";
    $headers  .= "From: $from\r\n";
    //options to send to cc+bcc
    //$headers .= "Cc: [email]maa@p-i-s.cXom[/email]";
    //$headers .= "Bcc: [email]email@maaking.cXom[/email]";
   
    // now lets send the email.
    mail($to, $subject, $message, $headers);

    echo "Message has been sent....!";
?>
User avatar
bigjoe11a
New php-forum User
New php-forum User
 
Posts: 128
Joined: Wed Aug 31, 2011 3:55 am
Location: USA

Re: PHP code to send an email

Postby jotorres1 » Thu Oct 27, 2011 3:29 pm

Hi,

Something with ur $smtp, not really sure though. I would suggest you take a look at this post, and see how easy I have done it.

http://www.jotorres.com/2011/10/simple-php-send-mail/

Just take a deep breath, and start all over, step by step, and you'll get it.

Hope it helps.
User avatar
jotorres1
New php-forum User
New php-forum User
 
Posts: 35
Joined: Thu Oct 27, 2011 1:24 pm


Return to PHP coding => Mail

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.