Jump to content
SkyRanger

HTML Email after submit

Recommended Posts

Email will send with the #$body  but will not send with the $body = str_replace

$the_kudo_image = '<img src=' . $kudobanner . '>';
$dir = plugin_dir_path( __DIR__ );
$template = file_get_contents( $dir .'/partials/kudos-email-template.html');
$emtemp = $dir .'/kudos/admin/partials/kudos-email-template.html';
    $body = str_replace(
      array(
        '{kudos_link}',
        '{the_kudo_image}',
        '{kudoagent}',
        '{kudoclient}',
        '{agentloc}',
        '{kudoposted}',
        '{kudomsg}'
      ),
      array(
        $kudos_link,
        $the_kudo_image,
        $kudoagent,
        $kudoclient,
        $agentloc,
        $kudoposted,
        $kudomsg
      ),
      $template
    );
    
    #$body = "testing email"; //commented out due to test body

    $to = "daveellis@eastlink.ca";
    
    $subject = "Kudos for $kudoagent";

    $headers = array('Content-Type: text/html; charset=UTF-8');
 	$headers .= 'From = Kudo Server <noreply@aciwork.cloudaccess.host>';
    $mail = @wp_mail( $to, $subject, $body, $headers );
   if($mail) {
  echo "<p>Mail Sent.</p>"; 
}
else {
  echo "<p>Mail Fault.</p>"; 

}   

 

Share this post


Link to post
Share on other sites

First, you should be using PHPMailer. It is much easier and has better control. What does the template contain? Did you print out what you read to make sure it is what you expect?

Share this post


Link to post
Share on other sites
Posted (edited)
1 minute ago, gw1500se said:

First, you should be using PHPMailer. It is much easier and has better control. What does the template contain? Did you print out what you read to make sure it is what you expect? What does "will not send" mean? It is not sending the email at all or is the sent email blank?

 

Edited by gw1500se

Share this post


Link to post
Share on other sites

As mentioned already you should be dumping out some of the vars to be sure they contain what you think they should.

Also - do you have php error checking on just to catch some errors you may have?  Such as $headers.  You first create it as an array but then you append a string to it.  I have no idea what you might have at that point so a var_dump of that would be important.   And - don't use the @ sign to suppress things.  If there is an error you should be handling it!  Plus the From assignment is incorrect (I believe).  It should be "From: xxx" not "From = xxx".

 

Share this post


Link to post
Share on other sites

Thanks guys, yeah forgot about the @ and yeah the $headers was incorrect.  They have been fixed but pulling no errors, template it populating properly as it is suppose and stating the email has been sent but not receiving.  Not sure if receiver server or outbound is blocking it. or it is just stating it is sending but not sending.

Share this post


Link to post
Share on other sites

This is the template file:  kudos-email-template.html and everythings shows correctly on check.  Also going to check out phpmailer

<html>

<head>
<meta content="en-ca" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 3</title>
<style type="text/css">
.auto-style1 {
	text-align: center;
}
</style>
</head>

<body>

<table style="width: 100%">
	<tr>
		<td class="auto-style1">View Online</td>
	</tr>
	<tr>
		<td><img src="buslogo.png" width="94" alt="" style="border-width:0; max-width:94px;height:auto; display:block" /></td>
	</tr>
	<tr>
		<td> </td>
	</tr>
	<tr>
		<td class="auto-style1">{kudomsg}</td>
	</tr>
	<tr>
		<td> </td>
	</tr>
	<tr>
		<td>
		<div style="color:#4b4f55; font-size:16px; margin-top: 60px; margin-bottom: 40px; text-align:left; font-family: Verdana, Geneva, sans-serif">
                          <div>
                            {kudoagent}
                          </div>
                          <div>
                            {kudoclient}
                          </div>
                          <div>
                            {agentloc}
                          </div>
                          <div>
                            {kudoposted}
                          </div>
                      </div>

		</td>
	</tr>
	<tr>
		<td> </td>
	</tr>
	<tr>
		<td> </td>
	</tr>
</table>

</body>

</html>

 

Share this post


Link to post
Share on other sites

I installed a mail logger/checker.  It is also showing no errors. Going to contact my service provider to see if it is being blocked on the server side.

Share this post


Link to post
Share on other sites

Are you able to send just a simple text email with a simple "hello world" message in it instead of all this other stuff?  Testing the ability to send emails is priority one now I think.

Share this post


Link to post
Share on other sites

Found out the problem. It is my ISP that is blocking the emails.  The mail guard program they are using is blocking the emails due to a url. I have contacted them and they have fixed the issue. HTML emails are working now.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.