Advertisement
Guest User

Untitled

a guest
Nov 11th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.73 KB | None | 0 0
  1. <?php
  2. /**
  3. * This example shows settings to use when sending via Google's Gmail servers.
  4. */
  5. //SMTP needs accurate times, and the PHP time zone MUST be set
  6. //This should be done in your php.ini, but this is how to do it if you don't
  7.  
  8. have access to that
  9. date_default_timezone_set('Etc/UTC');
  10. require('PHPMailer/class.phpmailer.php');
  11. $response = array("error" => TRUE);
  12. //Create a new PHPMailer instance
  13. $mail = new PHPMailer();
  14. //Tell PHPMailer to use SMTP
  15. $mail->isSMTP();
  16. //Enable SMTP debugging
  17. // 0 = off (for production use)
  18. // 1 = client messages
  19. // 2 = client and server messages
  20. $mail->SMTPDebug = 2;
  21. //Ask for HTML-friendly debug output
  22. $mail->Debugoutput = 'html';
  23. //Set the hostname of the mail server
  24. $mail->Host = 'smtp.gmail.com';
  25. // use
  26. // $mail->Host = gethostbyname('smtp.gmail.com');
  27. // if your network does not support SMTP over IPv6
  28. //Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
  29. $mail->Port = 587;
  30. //Set the encryption system to use - ssl (deprecated) or tls
  31. $mail->SMTPSecure = 'tls';
  32. //Whether to use SMTP authentication
  33. $mail->SMTPAuth = true;
  34. //Username to use for SMTP authentication - use full email address for gmail
  35. $mail->Username = "foodies.doof@gmail.com";
  36. //Password to use for SMTP authentication
  37. $mail->Password = "FmNy28(%";
  38. //Set who the message is to be sent from
  39. $mail->setFrom('foodies.doof@gmail.com', 'Mahmoud Nabegh');
  40. //Set an alternative reply-to address
  41. //$mail->addReplyTo('replyto@example.com', 'First Last');
  42. //Set who the message is to be sent to
  43. $mail->addAddress($_POST['email']);
  44. //Set the subject line
  45. $mail->Subject = 'PHPMailer GMail SMTP test';
  46. //Read an HTML message body from an external file, convert referenced images to embedded,
  47. //convert HTML into a basic plain-text alternative body
  48. $content = "<b>Welcome foodie, we hope your stomach will find its love :D</b>";
  49. $mail->MsgHTML($content);
  50. //Replace the plain text body with one created manually
  51. $mail->AltBody = 'This is a plain-text message body';
  52. //Attach an image file
  53. //$mail->addAttachment('images/phpmailer_mini.png');
  54. //send the message, check for errors
  55. if(!$mail->Send())
  56. echo "Problem sending email.";
  57. else
  58. echo "email sent.";
  59.  
  60. ?>
  61.  
  62. public void mail(View v)
  63. {
  64. String tag_string_req = "req_login";
  65. final String email = inputEmail.getText().toString();
  66.  
  67. pDialog.setMessage("Logging in ...");
  68. showDialog();
  69. //new StringRequest(the request method to use,the url to fetch the string at,Listener to receive the String response)
  70. //the POST method is an HTTP request method which submits data to be processed by the API
  71. StringRequest strReq = new StringRequest(Method.POST,
  72. AppConfig.URL_LOGIN, new Response.Listener<String>() {
  73.  
  74. @Override
  75. public void onResponse(String response) {
  76. Log.e(TAG, "Login Response: " + response.toString());
  77. hideDialog();
  78.  
  79. }
  80. }, new Response.ErrorListener() {
  81. //volleyerror in sending the request to the API
  82. // OnErrorResponse is called when some volley error such as no internet connection or if URL is invalid occur.
  83.  
  84. @Override
  85. public void onErrorResponse(VolleyError error) {
  86. Log.e(TAG, "Login Error: " + error.getMessage());
  87. Toast.makeText(getApplicationContext(),
  88. error.getMessage(), Toast.LENGTH_LONG).show();
  89. hideDialog();
  90. }
  91. }) {
  92.  
  93. @Override
  94. protected Map<String, String> getParams() {
  95. // Posting parameters to login url
  96. Map<String, String> params = new HashMap<String, String>();
  97. params.put("email", email);
  98. return params;
  99. }
  100.  
  101. };
  102.  
  103. // Adding request to request queue
  104. AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement