Guest User

Untitled

a guest
Jan 29th, 2018
1,136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.29 KB | None | 0 0
  1. if ( $message && !wp_mail($user_email, $title, $message) )
  2.  
  3. <?php
  4. /**
  5. * Plugin Name: Stackexchange Testplugin
  6. * Plugin URI: http://yoda.neun12.de
  7. * Description: Send me a test email
  8. * Version: 0.1
  9. * Author: Ralf Albert
  10. * Author URI: http://yoda.neun12.de
  11. * Text Domain:
  12. * Domain Path:
  13. * Network:
  14. * License: GPLv3
  15. */
  16.  
  17. namespace WordPressStackexchange;
  18.  
  19. add_action( 'init', __NAMESPACE__ . 'plugin_init' );
  20.  
  21. function plugin_init(){
  22. $to = 'your-email-adress@some-domain.tld';
  23. $subject = 'Testemail';
  24. $message = 'FooBarBaz Testmail is working';
  25.  
  26. wp_mail( $to, $subject, $message );
  27. }
  28.  
  29. define( 'WP_DEBUG', true );
  30. define( 'WP_DEBUG_LOG', true );
  31. define( 'WP_DEBUG_DISPLAY', true );
  32. @ini_set( 'display_errors',1 );
  33.  
  34. if (ini_get('safe_mode') || !($this->UseSendmailOptions)) {
  35. $rt = @mail($to, $this->encodeHeader($this->secureHeader($subject)), $body, $header);
  36. } else {
  37. $rt = @mail($to, $this->encodeHeader($this->secureHeader($subject)), $body, $header, $params);
  38. }
  39.  
  40. // Send!
  41. try {
  42. return $phpmailer->Send();
  43. } catch ( phpmailerException $e ) {
  44. //------------- This next line is the one to add -------------------
  45. if (WP_DEBUG) echo '<pre>' . esc_html(print_r($e, TRUE)) . '</pre>';
  46. return false;
  47. }
  48.  
  49. <?php
  50.  
  51. function sendgridmail($to, $subject, $message, $headers)
  52. {
  53. $url = 'https://api.sendgrid.com/';
  54. //$user = 'yourUsername';
  55. //$pass = 'yourPassword';
  56.  
  57. $params = array(
  58. 'api_user' => $user,
  59. 'api_key' => $pass,
  60. 'to' => $to,
  61. 'subject' => $subject,
  62. 'html' => '',
  63. 'text' => $message,
  64. 'from' => 'abc@hotmail.com',
  65. );
  66.  
  67.  
  68. $request = $url.'api/mail.send.json';
  69.  
  70. // Generate curl request
  71. $session = curl_init($request);
  72. // Tell curl to use HTTP POST
  73. curl_setopt ($session, CURLOPT_POST, true);
  74. // Tell curl that this is the body of the POST
  75. curl_setopt ($session, CURLOPT_POSTFIELDS, $params);
  76. // Tell curl not to return headers, but do return the response
  77. curl_setopt($session, CURLOPT_HEADER, false);
  78. curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
  79.  
  80. // obtain response
  81. $response = curl_exec($session);
  82. curl_close($session);
  83.  
  84. // print everything out
  85. //print_r($response);
  86. }
  87.  
  88. //only for testing:
  89. /*$to = 'abc@yahoo.com';
  90. $subject = 'Testemail';
  91. $message = 'It works!!';
  92. echo 'To is: ' + $to;
  93. #wp_mail( $to, $subject, $message, array() );
  94. sendgridmail($to, $subject, $message, $headers);
  95. print_r('Just sent!');*/
  96.  
  97. if (!function_exists('wp_mail')) {
  98. function wp_mail($to, $subject, $message, $headers = '', $attachments = array())
  99. {
  100. // use the PHP GnuPG library here to send mail.
  101. sendgridmail($to, $subject, $message, $headers);
  102. }
  103. }
  104.  
  105. function plugin_init()
  106. {
  107. /* $to = 'xyz@yahoo.com';
  108. $subject = 'Testemail';
  109. $message = 'It works Live!';
  110. //echo 'To is: ' + $to;
  111. wp_mail( $to, $subject, $message, array() );
  112. //print_r('Just sent!');*/
  113. }
  114.  
  115. @mail("example@exmaple.com",$title,$body,$headers,"-fexample@exmaple.com");
  116.  
  117. <?php
  118. $to = "example@gmail.com";
  119. $subject = "Test Email Function";
  120. $txt = "Hello world!";
  121. $headers = "From: webmaster@example.com" . "rn" .
  122. "CC: xyz@example.com";
  123.  
  124. mail($to,$subject,$txt,$headers);
  125. ?>
  126.  
  127. sudo apt-get install sendmail
Add Comment
Please, Sign In to add comment