Php test smtp server

chrisvoo / email_test.php

This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters

# use composer : php composer.phar require swiftmailer/swiftmailer @stable
require __DIR__ . ‘/vendor/autoload.php’ ;
// Approach 1: Change the global setting (suggested)
Swift_Preferences :: getInstance ()-> setCharset ( ‘utf-8’ );
$ smtp_host = ‘1.2.3.4’ ;
// Create the Transport
$ transport = Swift_SmtpTransport :: newInstance ( $ smtp_host , 25 );
// Create the Mailer using your created Transport
$ mailer = Swift_Mailer :: newInstance ( $ transport );
$ logger = new Swift_Plugins_Loggers_EchoLogger ();
$ mailer -> registerPlugin ( new Swift_Plugins_LoggerPlugin ( $ logger ));
// Pass it as a parameter when you create the message
$ message = Swift_Message :: newInstance ( ‘Subject here’ , ‘My amazing body’ );
$ message -> setFrom ( array ( ‘no-reply@host.it’ => ‘No reply’ ));
$ message -> setTo ( array ( ‘fromemail@mail.it’ => ‘Christian’ ));
// Or set it after like this
$ message -> setBody ( ‘My amazing body’ , ‘text/html’ );
// Send the message
if (! $ mailer -> send ( $ message , $ failures ))
echo » Failures: «;
print_r( $ failures );
> else
echo » Sent «;
>

Источник

Using PHP to test that an SMTP server is working properly

I am wondering if you all have come across and end to end test of an SMTP server which would: Send a test email from SMTP to another server Retreive that email presumably there would be an ID in the email so that if this was done on a regular basis, the sent email could be connected to the received email. Question: I have seen code out there to use PHP to Send an Email to an SMTP server but it does not mean that the email went out properly.

How to send email with SMTP in php

I want to send email with SMTP in my project, previously i write php mail() in my project but now my client want that i should use SMTP . I search about this but i get nothing any proper solution for this.

In my php mail() i send name, subject and comment, so how can i do this in SMTP .

$payer_email = "Your Email"; $subject = "Your Subject"; $message = 'Dear '.$name.', Thank you for your purchase from '.$site_url.'. The details of your purchase are below. Transaction ID: '.$txn_id.' Item Name: '.$item_name.' Payment Amount: '.$payment_amount.' Payment Amount: '.$payment_status.' Paid to: '.$receiver_email.' Thanks and Enjoy!'; $headers .= 'From: ' .$from. "\r\n" .'Reply-To: ' .$from . "\r\n"; $headers .= 'MIME-Version: 1.0' . "\r\n"; $headers .= "Content-Type: text/html; charset=iso-8859-1 "; //mail to buyer mail( $payer_email , $subject, $message, $headers ); 

Please give me some suggestions or simple and nice tutorials.

Take a look at PHP Mailer:

SMTPDebug = 3; // Enable verbose debug output $mail->isSMTP(); // Set mailer to use SMTP $mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = 'user@example.com'; // SMTP username $mail->Password = 'secret'; // SMTP password $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted $mail->Port = 587; // TCP port to connect to $mail->From = 'from@example.com'; $mail->FromName = 'Mailer'; $mail->addAddress('joe@example.net', 'Joe User'); // Add a recipient $mail->addAddress('ellen@example.com'); // Name is optional $mail->addReplyTo('info@example.com', 'Information'); $mail->addCC('cc@example.com'); $mail->addBCC('bcc@example.com'); $mail->WordWrap = 50; // Set word wrap to 50 characters $mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments $mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name $mail->isHTML(true); // Set email format to HTML $mail->Subject = 'Here is the subject'; $mail->Body = 'This is the HTML message body in bold!'; $mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; if(!$mail->send()) < echo 'Message could not be sent.'; echo 'Mailer Error: ' . $mail->ErrorInfo; > else
$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 

Create library file for the SMTP Settings ‘library.php’:

  Make the form post and do the below actions: IsSMTP(); $mail->Host = SMTP_HOST; //Hostname of the mail server $mail->Port = SMTP_PORT; //Port of the SMTP like to be 25, 80, 465 or 587 $mail->SMTPAuth = true; //Whether to use SMTP authentication $mail->Username = SMTP_UNAME; //Username for SMTP authentication any valid email created in your domain $mail->Password = SMTP_PWORD; //Password for SMTP authentication $mail->AddReplyTo("reply@yourdomain.com", "Reply name"); //reply-to address $mail->SetFrom("from@yourdomain.com", "Asif18 SMTP Mailer"); //From address of the mail // put your while loop here like below, $mail->Subject = "Your SMTP Mail"; //Subject od your mail $mail->AddAddress($email, "Asif18"); //To address who will receive this email $mail->MsgHTML("Hi, your first SMTP mail has been received. Great Job. 

by Asif18
"); //Put your body of the message you can place html code here $mail->AddAttachment("images/asif18-logo.png"); //Attach a file here if any or comment this line, $send = $mail->Send(); //Send the mails if($send)< echo '

Mail sent successfully

'; > else< echo '

Mail error:

'.$mail->ErrorInfo; > > ?>

Please edit your email and password correctly.

You may see the demo and source code on Click here

SMTP Authentication with PHP mail() function, The only way to this without more coding or using external library, is to update sendmail: Define SMTP Server. smtp_server=mail.mydomain.com. If you need to change the smtp and SSL ports ; smtp port (normally 25) smtp_port=25 ; SMTPS (SSL) support ; auto = use SSL for port 465, otherwise try to use TLS ; …

Using PHP to test that an SMTP server is working properly

I have seen code out there to use PHP to Send an Email to an SMTP server but it does not mean that the email went out properly.

I am wondering if you all have come across and end to end test of an SMTP server which would:

  1. Send a test email from SMTP to another server
  2. Retreive that email presumably there would be an ID in the email so that if this was done on a regular basis, the sent email could be connected to the received email.

Obviously this really would be testing the uptime of two servers and the inet connection between the two unless the SMTP server sent an email to itself.

The way I do it is to configure an account on the remote SMTP server to autoreply to messages. Put a unique value in the subject line so you can identify the message that comes back (like a timestamp) and send off the message.

Use a script to POP the message from the mailbox on the local server the reply goes into and read the unique value (or use IMAP to read the message; either works as well).

If you use a timestamp then it’s easy to measure how long it took for the roundtrip.

You’ll want to have a mechanism to regenerate your ping message if it gets lost or fails to return in a reasonable time.

If you would prefer not to go the roundtrip route then send your message and use POP/IMAP to read it from the account you sent it to. That’s even easier to do. -Rick

Smtp using php Code Example, Get code examples like «smtp using php» instantly right from your google search results with the Grepper Chrome Extension. Follow. GREPPER; SEARCH SNIPPETS; PRICING; FAQ; USAGE DOCS ; INSTALL GREPPER; Log In; All Languages >> PHP >> WordPress >> smtp using php “smtp using php” Code …

How to test php email using WAMP

I have wamp installed and am using it as my testing ground. I can’t however test the PHP mail() function as it always falls over.

Is this something that can be rectified?

Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp\www\functions.php on line 288 

I’ve also checked my php.ini setup and it looks as follows:

 [mail function] ; For Win32 only. ; http://php.net/smtp SMTP = localhost ; http://php.net/smtp-port smtp_port = 25 ; For Win32 only. ; http://php.net/sendmail-from sendmail_from = technical@clevermutt.com ; For Unix only. You may supply arguments as well (default: "sendmail -t -i"). ; http://php.net/sendmail-path ;sendmail_path = ; Force the addition of the specified parameters to be passed as extra parameters ; to the sendmail binary. These parameters will always replace the value of ; the 5th parameter to mail(), even in safe mode. ;mail.force_extra_parameters = ; Add X-PHP-Originating-Script: that will include uid of the script followed by the filename mail.add_x_header = On ; Log all mail() calls including the full path of the script, line #, to address and headers ;mail.log = 

You could use PHPMailer to point to an external SMTP server. Or you could use a simple script that dumps to a file. There are a couple of earlier questions on the same topic, with more ideas.

you have to modify your PHP.ini file settings to include an SMTP server, port and sendmail_from

 [mail function] ; For Win32 only. ; http://php.net/smtp SMTP = localhost ; http://php.net/smtp-port smtp_port = 25 

; For Win32 only. ; http://php.net/sendmail-from sendmail_from = you@yourdomain

install free argosoft mail argosoft and try whatever you want with mail in php

You can also use Gmail as SMTP server, that will work anywhere, on any server, any OS. If you use a Google Apps email account, you can even use your own custom From: email-address.

Google Apps: http://www.google.com/apps/

Php — Testing PHPMailer username and password, Note, this is not to check if you can connect to the SMTP, but actually check the username and password and return a result. I saw somewhere someone mentioned using the Connect() function, but I cannot get this working. Thanks.

SMTP server availability with PHP and telnet

My company is renting lot’s of IP’s. And our clients are mostly mailers. After IP lease, sometimes they make IP’s unusable, because IP’s gets blocked at certain providers, like Yahoo, Gmail, AOL etc.

Currently, we make a simple check this by binding the IP and running telnet command from our CentOS systems like the this:

telnet -b $IP smtp.gmail.com 25 

And get the output, if it is 220 for OK, or something else that would indicate that IP is not dirty .

What I am looking for is a PHP script, or first the idea how this can be done. Basically, we would bind IP’s, and PHP will check the output of the connection and write to a csv file for example.

I’ve done lots of php projects in the past, but nothing similar. Any idea from where to start? Thanks for suggestions.

Due my investigations, I am able to do something like this,

 $eol= system("nc -4 -w 2 -s $Binded_IP smtp.gmail.com 25", $output ); var_dump($output); 
-bash-4.2$ php script.php 220 smtp.gmail.com ESMTP 13sm2795405wml.25 - gsmtp 

I am trying with netcat instead telnet. This is the meaning of the arguments, to those who aren’t familiar with netcat:

-4 to bind only IPv4 -s Source IP to bind to -w 2 Timeout 

But the problem is I can not find a way to close that connection, it only hangs out, and remain open. If I find a way to close that connection, I could store $output in the file, filter SMTP status code, and continue with second IP and check it.

You can use the following script to check if there is a connection to the server.

$f = fsockopen('smtp smtp.gmail.com', 25) ; if ($f !== false) < $res = fread($f, 1024) ; if (strlen($res) >0 && strpos($res, '220') === 0) < echo "Success!" ; >else < echo "Error: " . $res ; >> fclose($f) ; 

How to send email with SMTP in php, I want to send email with SMTP in my project, previously i write php mail() in my project but now my client want that i should use SMTP. I search about this but i get nothing any proper solution for this. In my php mail() i send name, subject and comment, so how can i do this in SMTP. Here is my code:Code sample$mail->Body = ‘This is the HTML message body in bold!‘;$mail->AltBody = ‘This is the body in plain text for non-HTML mail clients’;if(!$mail->send()) ErrorInfo;Feedback

Источник

Читайте также:  Хорошие скрипты для html
Оцените статью