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 example@clientdomain.com

 

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 mygmail@gmail.com and from address should be example@clientdomain.com

 

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  = 'mygmail@gmail.com';

// Additional headers
$from = "example@clientdomain.com";

$headers["From"] = $from;
$headers["To"]    = 'mygmail@gmail.com'; 
$headers["Subject"] = "Test Email";

$headers  = array ('From' => $from,'To' => 'mygmail@gmail.com'); 

$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"]     = "mygmail@gmail.com";
$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 = "mygmail@gmail.com"; // SMTP username
$mail->Password = "mygmailpassword"; // SMTP password
$webmaster_email = "example@clientdomain.com"; //Reply to this email ID
$email="mygmail@gmail.com"; // 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.

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.