So I am using the PHPMailer library in PHP to send a welcome email when ever my users registered, and it takes so long to do this.
It takes around 30 - 50 seconds to act
Remote SMTP is not really a good thing to use during page submissions - it's often very slow (sometimes deliberately, for greetdelay checks), as you're seeing. The way around it is to always submit to a local (fast) mail server and let it deal with the waiting around, and also handle things like deferred delivery which you can't handle from PHPMailer. You also need to deal with bounces correctly when going that route as you won't get immediate feedback.
That you can often get away with direct delivery doesn't mean it's a reliable approach.
To see what part of the SMTP conversation is taking a long time, set $mailer->SMTPDebug = 2;
and watch the output (though don't do that on your live site!).
Don't know if PHPMailer is compulsory for you or not, but if it's not I am recommanding SwiftMailer .
as per my personal Experience It's Really fast and reliable.
Thanks.
include_once "inc/swift_required.php";
$subject = 'Hello from Jeet Patel, PHP!'; //this will Subject
$from = array('jeet@mydomain.com' =>'mydomain.com'); //you can use variable
$text = "This is TEXT PART";
$html = "<em>This IS <strong>HTML</strong></em>";
$transport = Swift_SmtpTransport::newInstance('abc.xyz.com', 465, 'ssl');
$transport->setUsername('MYUSERNAME@MYDOMAIN.COM');
$transport->setPassword('*********');
$swift = Swift_Mailer::newInstance($transport);
$to = array($row['email'] => $row['cname']);
$message = new Swift_Message($subject);
$message->setFrom($from);
$message->setBody($html, 'text/html');
$message->setTo($to);
$message->addPart($text, 'text/plain');
if ($swift->send($message, $failures))
{
echo "Send successfulllyy";
} else {
print_r($failures);
}