From charlesreid1

Line 26: Line 26:


==Opening Port==
==Opening Port==
The following iptables rule will keep track of outgoing packets and will allow corresponding return packets - necessary for SMTP connections, because you want to be able to receive the "okay, data received" signal from the server you're sending mail out to.
<pre>
iptables -I INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
</pre>
See [https://unix.stackexchange.com/questions/104954/how-to-allow-outgoing-smtp-on-iptables-debian-linux#104957]
==Using PHPMailer==


<pre>
<pre>
Line 56: Line 66:
?>
?>
</pre>
</pre>


=Flags=
=Flags=

Revision as of 10:48, 28 October 2017

Sending email with PHP:

https://stackoverflow.com/questions/14456673/sending-email-with-php-from-an-smtp-server#14456761

Procedure:

  • Open port 465
  • Put PHPMailer on your PHP include path
  • From the PHP script you want to send email from, include PHPMailer
  • Drop in your SMTP credentials
  • Now you're able to send off emails

Namecheap:

  • Username: your email address
  • Password: password for this email account
  • Incoming/outgoing servers name: mail.privateemail.com
  • Incoming server type: IMAP or POP3
  • Incoming server (IMAP): 993 port for SSL
  • Incoming server (POP3): 995 port for SSL
  • Outgoing server (SMTP): 465 port for SSL

Installing PHPMailer

Visit PHPMailer: https://github.com/PHPMailer/PHPMailer

Copy the contents of the PHPMailer folder into one of the include_path directories specified in your PHP configuration

Opening Port

The following iptables rule will keep track of outgoing packets and will allow corresponding return packets - necessary for SMTP connections, because you want to be able to receive the "okay, data received" signal from the server you're sending mail out to.

iptables -I INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT

See [1]

Using PHPMailer

<?php

//////////////////////////////////////////////////////////////
// Include PHP mailer stuff

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'path/to/PHPMailer/src/Exception.php';
require 'path/to/PHPMailer/src/PHPMailer.php';
require 'path/to/PHPMailer/src/SMTP.php';

//////////////////////////////////////////////////////////////
// Set SMTP credentials

$mail = new PHPMailer();
$mail->IsSMTP();
$mail->CharSet = 'UTF-8';

$mail->Host       = "mail.example.com"; // SMTP server example
$mail->SMTPDebug  = 0;                     // enables SMTP debug information (for testing)
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->Port       = 25;                    // set the SMTP port for the GMAIL server
$mail->Username   = "username"; // SMTP account username example
$mail->Password   = "password";        // SMTP account password example

?>

Flags