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:
require_once “Mail.php”;
$username = ‘[email protected]’;
$password = ‘password’;
$smtpHost = ‘127.0.0.1’;
$smtpPort = ‘465’;
$to = ‘[email protected]’;
$from = ‘[email protected]’
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( '[email protected]', $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 = '[email protected]';
$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.