Thursday 15 August 2013

authentication - GMail SMTP avoid using direct password in PHP code -


I am going to use PHP to send email. My PHP should be on a shared host I got an opportunity to send emails through PHP, but I'm worried about writing a valid password in PHP code. Does PHP or GMMT SMTP server provide a way to avoid using direct passwords? Probably something similar to API authentication? I have not really tried to send emails just like a SMTP server like Google, because all of these services Certification Required There are some great projects in Jitub, which allow SMT to send email using secure ports, authentication, SSL etc. (Remember that PHP files are server-side, so users can not access this information, so you have secured.)

And if you go to your repo, you will get a sample of them:

  & lt ;? Php is required 'class.phpmailer.php'; $ Mail = new PHPMailer; $ Mail & gt; IsSMTP (); // Set up the mailer to use the SMTP $ mail-> host = 'smtp1.example.com; Smtp2.example.com '; // Specify the main and backup servers $ mail- & gt; SMTPAuth = true; // Enable SMTP authentication $ Mail- & gt; User name = 'jsan'; // SMTP username $ mail- & gt; Password = 'secret'; // SMTP Password $ Mail- & gt; SMTPSecure = 'TLS'; // Enable Encryption, 'SSL' also has $ Mail- & gt; Accepted from; = 'From@example.com'; $ Mail- & gt; Sainam = 'mailer'; $ Mail- & gt; AddAddress ('josh@example.net ',' Josh Adams'); // Add a recipient $ Mail- gt; AddAddress ('ellen@example.com '); // name is optional $ mail- & gt; AddReplyTo ('info@example.com', 'Notifications'); $ Mail & gt; AddCC ('cc@example.com '); $ Mail & gt; AddBCC ('bcc@example.com '); $ Mail-> WordWrap = 50; // Set the word wrap to 50 characters $ mail- & gt; AddAttachment ('/ var / tmp / file.tar.gz'); // Add attachment $ Mail-> AddAttachment ('/ tmp / image.jpg', 'new.jpg'); // Alternative Name $ Mail- & gt; Is HTML (true); // html email mail format set for mail- mail-> Subject = 'this is the subject'; $ Mail- & gt; Body = 'This is the main part of the HTML message & lt; B & gt; Bold! & Lt; / B & gt; '; $ Mail- & gt; AltBody = 'This is the body in plain text for non-HTML mail client'; If (! $ Mail- & gt; send ()) {echo 'message could not be sent'. '; Echo 'mailer error:' $ Mail & gt; ErrorInfo; Go out; } 'Message has been sent';   

But if you do not want to go and the password on the hard code php controller or whatever you will be used to take action on email, then you should always send the email to the php Can be used.

Find a simple sample on the document:

  & lt ;? Php $ to = 'nobody@example.com'; $ Theme = 'subject'; $ Message = 'hello'; $ Headers = 'From: webmaster@example.com' "\ r \ n" 'Answer: webmaster@example.com' "\ r \ n" 'X-Mailer: PHP /' phpversion (); Mail ($ $ $ $ theme, $ message, $ headers); ? & Gt;   

This function is an SMTP method of sending an email, but authentication is always necessary but in this case it is done with the server, so all the headers must be set to send one Correct Email

Note that some server providers do not send email to this function correctly, so at the end you will need to create or use a php SMTP email class to process email, And this f Ail should be password

No comments:

Post a Comment