Jump to content

SMTP Mail Function


mysmsmantra

Recommended Posts

Hi PHP Developers,

I am trying to integrate php mail script on my website mysmsmantra but getting error such as

Fatal error: Uncaught Error: Call to undefined method PEAR_Error::send() in /home/website/public_html/mysmsmantra.com/sendmail2.php:99 Stack trace: #0 {main} thrown in /home/website/public_html/mysmsmantra.com/sendmail2.php on line 99

I am using below code to send mail

 <?php
require_once "recaptchalib.php";

// your secret key
$secret = "xxxxxxxxxxxxxx";
 
// empty response
$response = null;
 
// check secret key
$reCaptcha = new ReCaptcha($secret);

if ($_POST["g-recaptcha-response"]) {
    $response = $reCaptcha->verifyResponse(
        $_SERVER["REMOTE_ADDR"],
        $_POST["g-recaptcha-response"]
    );
}


if ($response != null && $response->success) {
require_once "Mail.php";

$pcount=0;
$gcount=0;
 $file="";
    
 $from=$_POST['email'];
    
 $from2='info@yourdomain.com';
 $name=$_REQUEST['name'];

 $from = "".$name." <".$_POST['email'].">";

 $to = "info@yourdomain.com";

 $subject = "Mail from mysmsmantra";

while (list($key,$val)=each($_POST))
        {
        if($key!='submit' && $key!='g-recaptcha-response')
        {
        $pstr = $pstr."$key : $val \n ";
        ++$pcount;
        }
        }
        while (list($key,$val)=each($_GET))
        {
        if($key!='submit' && $key!='g-recaptcha-response')
        {
        $gstr = $gstr."$key : $val \n ";
        ++$gcount;
        }
        }

 if ($pcount > $gcount)
        {
        $message_body=$pstr;

        }
else
        {
        $message_body=$gstr;


        }

 
 
$host = "ssl://secure.emailsrvr.com";
 $port = "465";
 $username = "info@yourdomain.com";
 $password = "xxxxxxx";    
 
 $headers = array ('From' => $from,
   'To' => $to,
   'Subject' => $subject);

 $headers2 = array ('From' =>$from2 ,
   'To' => $from,
   'Subject' => $subject);

 $smtp = Mail::factory('smtp',
   array ('host' => $host,
     'port' => $port,
     'auth' => true,
     'username' => $username,
     'password' => $password));
 
 $mail = $smtp->send($to, $headers, $message_body);
 
 if (PEAR::isError($mail)) {
   echo("<p>" . $mail->getMessage() . "</p>");
  } else {
   //echo("<p>Message successfully sent!</p>");
      header( "Location: thankyou.html"); 
  }
}
else {
    if(isset($_SERVER['HTTP_REFERER'])) {
    $ref= $_SERVER['HTTP_REFERER'];
}
    header("Location: ".$ref.""); 
  }

        
        ?>

 

Edited by mysmsmantra
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.