Page 1 of 1

[TASK] Sending an Email with SMTP Protocol (Simple Course)

PostPosted: Mon Apr 25, 2016 2:42 pm
by admin
We will go through an example of sending an Email by PHPoC Blue or Black.

There are two popular protocols to send Email: SMTP and ESMTP.
PHPoC supports libraries for both prototol. Depending on your mail server, you might use SMTP or ESMTP protocol. For example, Gmail uses ESMTP, so, to send email from a Gmail account, you need to use ESMTP library.

This example is a simple course uses the SMTP library.
For sending email using ESMTP protocol, refer to this example

Source Codes
1. task0.php
Code: Select all

<?php

if(_SERVER("REQUEST_METHOD"))
    exit; // avoid php execution via http request

include_once "/lib/sn_dns.php";
include_once "/lib/sn_smtp.php";

echo "PHPoC example : send email\r\n";

//smtp_setup(udp_id, tcp_id, "x.x.x.x");
//smtp_hostname("from_domain.com");
//smtp_account("from_id@from_domain.com", "from_name");

$subject = "email test from PHPoC";
$message = "This is PHPoC test email\r\nGood bye\r\n";

$msg = smtp_send("to_id@to_domain.com", "to_name", $subject, $message);

if(
$msg == "221")
    echo "send email successful\r\n";
else
    echo "send email failed\r\n";

?>


How to use

1. Make sure that your PHPoC Blue or Black is connected to the Internet.

2. Please download a PSP (PHPoC Support Package) of libraries and examples from PHPoC.

3. Connect PHPoC Blue or Black to your PC via USB cable.

4. Run PHPoC Debugger.

5. Upload all libraries in PSP to your PHPoC Blue or Black through PHPoC Debugger.
In fact, you only need to upload sn_dns.php and sn_smtp.php files to use in this example. But for future use, you can upload all.
psp_email_eg_01.png
psp_email_eg_01.png (9 KiB) Viewed 5116 times

※ Note that the libraries should be located in the /lib folder.
psp_email_eg_02.png
psp_email_eg_02.png (8.84 KiB) Viewed 5116 times


6. Find an example of E-mail (SMTP) in the PSP.
psp_email_eg_03.png
psp_email_eg_03.png (10.83 KiB) Viewed 5116 times


7. Upload init.php and task0.php files to your PHPoC Blue or Black.
※ Note that the init.php and task0.php files should be located in the root folder.
psp_email_eg_04.png
psp_email_eg_04.png (2.22 KiB) Viewed 5116 times


8. Modify the e-mail address and name to yours in task0.php file. (line number 18)
psp_email_eg_05.png
psp_email_eg_05.png (20.65 KiB) Viewed 5116 times


9. Upload the task0.php to your PHPoC Blue or Black again.

10. Run the example.
psp_email_eg_06.png
psp_email_eg_06.png (52.24 KiB) Viewed 5116 times