Jump to content

How to send email using Gmail credentials and other domain in from address


zohab

Recommended Posts

Hi,

 

I am trying to send email using pear email and php mailer with gmail account credentials and from address [email protected]

 

but it is not working.

 

Either it shows only gmail email in from or email sending did not work.

 

Basically I want to send email using credentials [email protected] and from address should be [email protected]

 

Any solution for this problem?

 

PEAR EMAIl EXAMPLE

 

error_reporting(E_ALL);
// Require Pear Mail Packages
include("pearemail/Mail.php");
include("pearemail/Mail/mime.php");


$to  = '[email protected]';

// Additional headers
$from = "[email protected]";

$headers["From"] = $from;
$headers["To"]    = '[email protected]'; 
$headers["Subject"] = "Test Email";

$headers  = array ('From' => $from,'To' => '[email protected]'); 

$adminMessage = "Test Email";

$crlf = "\n";

$mime = new Mail_mime($crlf);

$mime->setHTMLBody($adminMessage);
$adminMessage = $mime->get();
$headers = $mime->headers($headers);
$params["host"]    = 'smtp.gmail.com';
$params["auth"]    = true; // note: there are *no delimiters*
$params["username"]     = "[email protected]";
$params["password"]     = "mygmailpassword"; 

$mail_message =& Mail::factory('smtp', $params);
$mail_message->send ($to, $headers, $adminMessage);

PHP MAILER EXAMPLE

 

 

<?php

//require("phpmailer/class.phpmailer.php");
include("class.phpmailer.php");
$mail = new PHPMailer();
$mail->Host = "ssl://smtp.gmail.com::465";
$mail->SMTPSecure = "ssl";
$mail->IsSMTP(); // send via SMTP
//IsSMTP(); // send via SMTP
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "[email protected]"; // SMTP username
$mail->Password = "mygmailpassword"; // SMTP password
$webmaster_email = "[email protected]"; //Reply to this email ID
$email="[email protected]"; // Recipients email ID
$name="name"; // Recipient's name
$mail->SetFrom = $webmaster_email;
$mail->FromName = "Webmaster";
$mail->AddAddress($email,$name);
$mail->AddReplyTo($webmaster_email,"Webmaster");
$mail->WordWrap = 50; // set word wrap
//$mail->AddAttachment("/var/tmp/file.tar.gz"); // attachment
//$mail->AddAttachment("/tmp/image.jpg", "new.jpg"); // attachment
$mail->IsHTML(true); // send as HTML
$mail->Subject = "This is the subject";
$mail->Body = "Hi,
This is the HTML BODY "; //HTML Body
$mail->AltBody = "This is the body when user views in plain text format"; //Text Body
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}
?> 

 

Thanks

Zohaib.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.