zohab Posted August 26, 2012 Share Posted August 26, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/267589-how-to-send-email-using-gmail-credentials-and-other-domain-in-from-address/ Share on other sites More sharing options...
trq Posted August 26, 2012 Share Posted August 26, 2012 Have you got your domain setup with Google apps? It's not going to happen otherwise. Quote Link to comment https://forums.phpfreaks.com/topic/267589-how-to-send-email-using-gmail-credentials-and-other-domain-in-from-address/#findComment-1372529 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.