GenX Posted July 31, 2023 Share Posted July 31, 2023 Hi all. Recently I've migrated my website to another hosting provider and now I'm having problems with sendmail php function. The old hosting server was allowing to send email under any mail account regardless of whether it is present on the server or belongs to the client, using the X-Envelope. Because the previous server configuration method is outdated and poses an increased risk the new Hosting provider doesn't allow such configuration so the script must be modified in order to send all mail authenticated through the local server. But I know little to nothing PHP, not a web developer, so I really hope you can help me solve this issue. In the functions.php file there are 2 script codes that send email for different purpose, but I'll post a few code snippets as I don't know which one should be changed. I need the code bellow to send the mail authenticated, something like: smtp_server=<smtp_server_address> smtp_port=25 smtp_ssl=auto auth_username="<SMTP_username>" auth_password="<SMTP_password>" or require_once "Mail.php"; $username = 'local@mail.com'; $password = 'password'; $smtpHost = '127.0.0.1'; $smtpPort = '465'; $to = 'mail@to.com'; $from = 'user@gmail.com' Code snippet 1: $emailTo = get_option('admin_email'); $subject = "Order A"; function set_html_content_type() { return 'text/html'; } add_filter( 'wp_mail_content_type', 'set_html_content_type' ); add_filter('wp_mail_from', 'new_mail_from'); add_filter('wp_mail_from_name', 'new_mail_from_name'); function new_mail_from($old) { return 'no-reply@'.$_SERVER['HTTP_HOST']; } function new_mail_from_name($old) { return 'Picky Ins'; } add_filter( 'wp_mail_content_type', 'set_html_content_type' ); $mail_raion = get_post_meta( $_POST['raion'], 'region_e-mail' , true ); $emailTo = get_option('admin_email'); $multiple_recipients = array( $mail_raion, $emailTo ); Code snippet 2: $emailTo = $transaction->email; $subject = "New Order"; add_filter( 'wp_mail_content_type', function() { return 'text/html'; }); add_filter('wp_mail_from', function() { return 'no-reply@'.$_SERVER['HTTP_HOST']; }); add_filter('wp_mail_from_name', function() { return 'Picky Ins'; }); $text = "<b>Hello,</b><br/> <p>Thank you...Text</p><br/> <b>Nice trip</b>"; $attachments = array( 'pdf_file/'.$name, get_attached_file(1715) ); function set_html_content_type() { return 'text/html'; } add_filter( 'wp_mail_content_type', 'set_html_content_type' ); wp_mail($emailTo, $subject, $text, null, $attachments); wp_mail( 'my-email@mail.com', $subject, $text, null, $attachments); remove_filter( 'wp_mail_content_type', 'set_html_content_type' ); if ($from_callback) { wp_redirect(get_permalink(1620).'?key='.$name); } } elseif($response['RESULT'] == 'OK' && $transaction->type == 1) { if ($from_callback) { wp_redirect(get_permalink(2830)); } } else { if ($from_callback) { $data_trans['post_title'] = 'Error'; $data_trans['set_html_content_type'] = 'YES'; sendMailAchitaPolitadeAsigurare($data_trans,$transaction->trans_id); wp_redirect(get_permalink(2876).'?transaction_error'); } } } Code snippet 3: add_post_meta( $postId, '_trans_id',$_trans_id, true ); $subject = $_data['post_title']; if(isset($_data['set_html_content_type'])) { function set_html_content_type() { return 'text/html'; } } add_filter( 'wp_mail_content_type', 'set_html_content_type' ); add_filter('wp_mail_from', 'new_mail_from'); add_filter('wp_mail_from_name', 'new_mail_from_name'); function new_mail_from($old) { return 'no-reply@'.$_SERVER['HTTP_HOST']; } function new_mail_from_name($old) { return 'Picky Ins'; } add_filter( 'wp_mail_content_type', 'set_html_content_type' ); $emailTo1 = 'my-email@mail.com'; $multiple_recipients = array( $emailTo1 ); // wp_mail($multiple_recipients, $subject, $text); sendEmailSimple($emailTo1, $subject, 'no-reply@'.$_SERVER['HTTP_HOST'], 'Picky Ins', '', $text); remove_filter( 'wp_mail_content_type', 'set_html_content_type' ); } Thank you in advance, Quote Link to comment Share on other sites More sharing options...
ginerjm Posted August 1, 2023 Share Posted August 1, 2023 All of this code does not help to understand your issues. The main thing though is your switch to an apparently newer and more up-to-date host is that you can no longer use an 'outside' email as the 'from' address for mail. I do believe that most hosts now insist that you use a domain hosted by that host to use as your sending email. Consequently you cannot use gmail from your domain. Your new hosting account must be providing for you a mail service using your new associated domain name and you will have to use that. And why wouldn't you? You do have a new domain with this host, don't you? And you have moved your domain to this new host? Unless the old domain was being handled by your old host and not technically 'yours'. In that case you do have an issue. I realize that you are not a developer but you are in PHP waters when you are dealing with what appears to be WordPress app that needs to be adjusted to use a new email account. First thing to know is that there is no 'sendmail' function in PHP. That may be a WP function in which case you won't get help here unless it's from a member who does WP himself. Since you've been posted here for 24 hours and you have no response other than from me, perhaps you need to start a new clearer and simpler question on how to 'change my WP mail for a new host' or something like that. Could get you some quicker follow-up. Hope this helps Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.