Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Okay, as promised, here's a way to avoid the errors by using PHPMailer. If you didn't know if PHPMAiler is for you, trust me I had the same issue, but it's extraordinary easy to use. </p> <p>Here's the code</p> <pre><code> $mail = new PHPMailer; $mail-&gt;isSMTP(); $mail-&gt;Host = "localhost"; $mail-&gt;SMTPAuth = true; $mail-&gt;Username = $Agentmail; $mail-&gt;Password = $smptpass; $mail-&gt;From = $Agentmail; $mail-&gt;FromName = $companyname; $mail-&gt;addAddress($email, $CustomerFullName); $mail-&gt;addReplyTo($Agentmail, $fullname); $mail-&gt;isHTML(true); $mail-&gt;Subject = $subject; $mail-&gt;Body = $body; $mail-&gt;altBody = $altBody; if(!$mail-&gt;send()) { header("location:errorpage.php"); } </code></pre> <p>Okay, so these are all variables. And it works perfect. One thing, if you are making a commercial system and you are worried about storing passwords in the database in plain text, as you should be, you don't have too! Encrypt them when you store them and decrypt them before using them for PHP Mailer.</p> <p>For the code above, I first decrypt the password:</p> <pre><code> $cipher = new Cipher('encrypt'); $smptpass = $cipher-&gt;decrypt($cipheredpass); </code></pre> <p>For this and PHPMailer to work, you need two files:</p> <pre><code>require_once "./PHPMailer/class.phpmailer.php"; require_once "functions.php"; </code></pre> <p>PHPMailer is stored in folder with the same name for me, so change your path to wherever you put it. As for functions.php, here's how to handle the encrypt/decrypt:</p> <pre><code>&lt;?php class Cipher { private $securekey; function __construct($textkey) { $this-&gt;securekey = md5($_SERVER['SERVER_ADDR']); } function encrypt($input) { return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $this-&gt;securekey, $input, MCRYPT_MODE_ECB)); } function decrypt($input) { return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $this-&gt;securekey, base64_decode($input), MCRYPT_MODE_ECB)); } } ?&gt; </code></pre> <p>As you can see, I'm using <code>$_SERVER</code> to pickup an environment variable, as system will be hosted on various machines, so I need something that always exists. After that, I <code>md5()</code> it, just for extra security. You can put anything you want as your key, it really doesn't matter, I'm trying to avoid having the same key on multiple systems. You don't need to store the key anywhere. If you have functions.php file like this, here's how to use it further:</p> <pre><code>$cipher = new Cipher('encrypt'); $variable = $cipher-&gt;encrypt($input); // For encrypting $cipher = new Cipher('decrypt'); $variable = $cipher-&gt;decrypt($input); // For decrypting </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload