1

How can I configure PHPMailer on localhost to send email by connecting through a proxy, as the direct connectivity to smtp server (smtp.google.com) is blocked by the network admin.

Also guide me if there is a substitute for PHPMailer that can use proxy, in case proxies can't be configured for PHPMailer.

Please guide.

I am using following code to send email:

<?php
require 'send/PHPMailerAutoload.php';

$info = $_POST['msg1']; 
$data = json_decode(stripslashes($info));

$email = $data->email;
$fName = $data->fName; 

$mail = new PHPMailer;

$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'abc@gmail.com';
$mail->Password = '**********';
$mail->SMTPSecure = 'tls';

$mail->From = 'abc@gmail.com';
$mail->FromName = 'ABC';
$mail->addAddress($email, $fName); 
$mail->addReplyTo('abc@gmail.com', 'ABC');

$mail->WordWrap = 50;
$mail->isHTML(true);

$mail->Subject = 'demo msg';
$mail->Body    = "hello friend!!";

if(!$mail->Send())
{
  echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
  echo "Message sent!";
}


?>
A. Sinha
  • 2,666
  • 3
  • 26
  • 45
  • possible duplicate :http://stackoverflow.com/questions/16048347/send-email-using-gmail-smtp-server-through-php-mailer – SnakeFoot Mar 31 '16 at 07:23
  • see my previous post http://stackoverflow.com/a/35263987/4098311 – Halayem Anis Mar 31 '16 at 08:02
  • 1
    Neither of those are duplicates - they just answer the generic question of sending through gmail - this question is about sending through a proxy. – Synchro Mar 31 '16 at 15:48
  • Possible duplicate of [Sending emails from PHPMailer using proxies IP addresses](http://stackoverflow.com/questions/36137999/sending-emails-from-phpmailer-using-proxies-ip-addresses) – Synchro Mar 31 '16 at 15:54

2 Answers2

0

PHPMailer has no explicit SMTP proxy support, but that doesn't mean you can't use proxies. You need to look at this question, which uses socat to create a proxy tunnel and sends through it using PHPMailer.

Community
  • 1
  • 1
Synchro
  • 35,538
  • 15
  • 81
  • 104
0

Defining protocol before the domain name would prevent the connectivity with SMTP Server getting stuck with HTTP Proxy.

For Example:

$mail->Host = 'tls://smtp.office365.com';