Minor fixes, code style

This commit is contained in:
Marcus Bointon 2016-08-31 10:26:06 +02:00
parent abd34cb809
commit 1e53c07286
6 changed files with 28 additions and 19 deletions

View File

@ -91,10 +91,8 @@ try {
$example_code .= "\n\$mail->Host = \"" . $_POST['smtp_server'] . "\";";
$example_code .= "\n\$mail->Port = \"" . $_POST['smtp_port'] . "\";";
$example_code .= "\n\$mail->SMTPSecure = \"" . strtolower($_POST['smtp_secure']) . "\";";
$example_code .= "\n\$mail->SMTPAuth = " . (array_key_exists(
'smtp_authenticate',
$_POST
) ? 'true' : 'false') . ";";
$example_code .= "\n\$mail->SMTPAuth = " .
(array_key_exists('smtp_authenticate', $_POST) ? 'true' : 'false') . ";";
if (array_key_exists('smtp_authenticate', $_POST)) {
$example_code .= "\n\$mail->Username = \"" . $_POST['authenticate_username'] . "\";";
$example_code .= "\n\$mail->Password = \"" . $_POST['authenticate_password'] . "\";";

View File

@ -12,6 +12,7 @@ require '../vendor/autoload.php';
if (array_key_exists('to', $_POST)) {
$err = false;
$msg = '';
$email = '';
//Apply some basic validation and filtering to the subject
if (array_key_exists('subject', $_POST)) {
$subject = substr(strip_tags($_POST['subject']), 0, 255);
@ -55,9 +56,9 @@ if (array_key_exists('to', $_POST)) {
$mail->Host = 'localhost';
$mail->Port = 2500;
$mail->CharSet = 'utf-8';
//It's important not to use the submitter's address as the form address as it's forgery,
//which will cause our messages to fail SPF checks
//Use an address in your own domain here
//It's important not to use the submitter's address as the from address as it's forgery,
//which will cause your messages to fail SPF checks.
//Use an address in your own domain as the from address, put the submitter's address in a reply-to
$mail->setFrom('contact@example.com', (empty($name)? 'Contact form': $name));
$mail->addAddress($to);
$mail->addReplyTo($email, $name);

View File

@ -6,7 +6,8 @@
*
*
* STEP 1 - Creating a certificate:
* You can either use a self signed certificate, pay for a signed one or use free alternatives such as StartSSL/Comodo etc.
* You can either use a self-signed certificate, pay for a signed one,
* or use free alternatives such as StartSSL, Comodo etc.
* Check out this link for more providers: http://kb.mozillazine.org/Getting_an_SMIME_certificate
* In this example I am using Comodo.
* The form is directly available via https://secure.comodo.com/products/frontpage?area=SecureEmailCertificate

View File

@ -51,6 +51,7 @@ if (!isset($_GET['code']) && !isset($_GET['provider'])) {
<a href='?provider=Yahoo'>Yahoo</a><br/>
<a href='?provider=Microsoft'>Microsoft/Outlook/Hotmail/Live/Office365</a><br/>
</body>
</html>
<?php
exit;
}
@ -71,11 +72,12 @@ if (!in_array($providerName, ['Google', 'Microsoft', 'Yahoo'])) {
exit('Only Google, Microsoft and Yahoo OAuth2 providers are currently supported in this script.');
}
//These details obtained are by setting up app in Google developer console.
//These details are obtained by setting up an app in the Google developer console,
//or whichever provider you're using.
$clientId = 'RANDOMCHARS-----duv1n2.apps.googleusercontent.com';
$clientSecret = 'RANDOMCHARS-----lGyjPcRtvP';
//If this automatic URL doesn't work, set it yourself manually
//If this automatic URL doesn't work, set it yourself manually to the URL of this script
$redirectUri = (isset($_SERVER['HTTPS']) ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
//$redirectUri = 'http://localhost/PHPMailer/redirect';
@ -87,6 +89,7 @@ $params = [
];
$options = [];
$provider = null;
switch ($providerName) {
case 'Google':
@ -111,6 +114,11 @@ switch ($providerName) {
break;
}
if (is_null($provider)) {
echo 'Provider missing';
exit;
}
if (!isset($_GET['code'])) {
// If we don't have an authorization code then get one
$authUrl = $provider->getAuthorizationUrl($options);

View File

@ -1228,7 +1228,8 @@ class PHPMailer
if ($this->has8bitChars($domain) and @mb_check_encoding($domain, $this->CharSet)) {
$domain = mb_convert_encoding($domain, 'UTF-8', $this->CharSet);
//Ignore IDE complaints about this line - method signature changed in PHP 5.4
if (false !== ($punycode = idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46))) {
$errorcode = 0;
if (false !== ($punycode = idn_to_ascii($domain, $errorcode, INTL_IDNA_VARIANT_UTS46))) {
return substr($address, 0, $pos) . $punycode;
}
}

View File

@ -5,18 +5,18 @@
#Create a temp folder to put messages in
numPath="${TMPDIR-/tmp/}fakemail"
umask 037
mkdir -p $numPath
mkdir -p ${numPath}
if [ ! -f $numPath/num ]; then
echo "0" > $numPath/num
if [ ! -f ${numPath}/num ]; then
echo "0" > ${numPath}/num
fi
num=`cat $numPath/num`
num=$(($num + 1))
echo $num > $numPath/num
num=`cat ${numPath}/num`
num=$((${num} + 1))
echo ${num} > ${numPath}/num
name="$numPath/message_$num.eml"
name="${numPath}/message_${num}.eml"
while read line
do
echo $line >> $name
echo ${line} >> ${name}
done
exit 0