<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://kb.rvmgroup.it/index.php?action=history&amp;feed=atom&amp;title=Inviare_email_tramite_php</id>
	<title>Inviare email tramite php - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://kb.rvmgroup.it/index.php?action=history&amp;feed=atom&amp;title=Inviare_email_tramite_php"/>
	<link rel="alternate" type="text/html" href="https://kb.rvmgroup.it/index.php?title=Inviare_email_tramite_php&amp;action=history"/>
	<updated>2026-05-06T22:47:41Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.44.2</generator>
	<entry>
		<id>https://kb.rvmgroup.it/index.php?title=Inviare_email_tramite_php&amp;diff=5021&amp;oldid=prev</id>
		<title>Gabriele.vivinetto at 19:04, 5 January 2007</title>
		<link rel="alternate" type="text/html" href="https://kb.rvmgroup.it/index.php?title=Inviare_email_tramite_php&amp;diff=5021&amp;oldid=prev"/>
		<updated>2007-01-05T19:04:45Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{stub}}&lt;br /&gt;
&lt;br /&gt;
Installare il pacchetto &lt;br /&gt;
&lt;br /&gt;
 apt-get install libphp-phpmailer&lt;br /&gt;
&lt;br /&gt;
PHP doesn&amp;#039;t allow you to send emails with SMTP authentication through the common command mail().&lt;br /&gt;
&lt;br /&gt;
When you write scripts to send mails your server won&amp;#039;t recognize you and sometimes will block your email except for the local network. &lt;br /&gt;
&lt;br /&gt;
You also need authentication to send HTML Mails&lt;br /&gt;
&lt;br /&gt;
To overcome this you should write a script to directly connect to SMTP socket passing parameters to the mail server through it.&amp;lt;br /&amp;gt;As it is an hard work and require a good knowledge on sockets and PHP programming, every &amp;quot;normal&amp;quot; PHP user can download and install PHPmailer (http://phpmailer.sourceforge.net/).&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;This PHP application includes many options, but we are focusing on simple use of authentication protocol. The installation need a folder (Ex. /PHPmailer) and 2 classes:&lt;br /&gt;
* class.phpmailer.php&lt;br /&gt;
* class.smtp.php&amp;lt;br /&amp;gt;These are the 2 files you must have in your new folder with the /language folder.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;The other files you will find in the .zip are /docs (examples described), /test (testing installation), /phpdocs (documentation) and don&amp;#039;t need to be uploaded onto your site.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;After you copy the files on your site you will be able to use PHPmailer in this way:&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&amp;#039;&amp;#039;&amp;#039;1. insert&amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;div class=&amp;quot;codetop&amp;quot;&amp;gt;CODE&amp;lt;/div&amp;gt;&amp;lt;div class=&amp;quot;codemain&amp;quot;&amp;gt;require(&amp;quot;phpmailer/class.phpmailer.php&amp;quot;); &amp;lt;/div&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;in your .php file to load the functions.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&amp;#039;&amp;#039;&amp;#039;2. use this code to send a mail: &amp;#039;&amp;#039;&amp;#039;&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;div class=&amp;quot;codetop&amp;quot;&amp;gt;CODE&amp;lt;/div&amp;gt;&amp;lt;div class=&amp;quot;codemain&amp;quot;&amp;gt;$mail = new PHPMailer(); //Create PHPmailer class &amp;lt;br /&amp;gt;$mail-&amp;gt;From = &amp;quot;youremail@yourdomain.com&amp;quot;; //Sender address &amp;lt;br /&amp;gt;$mail-&amp;gt;FromName = &amp;quot;Name to Display &amp;quot;; //The name that you&amp;#039;ll see as Sender&amp;lt;br /&amp;gt;$mail-&amp;gt;Host = &amp;quot;mail.youdomain.com&amp;quot;; //Your SMTP mail server &amp;lt;br /&amp;gt;$mail-&amp;gt;Mailer = &amp;quot;smtp&amp;quot;; //Protocol to use &amp;lt;br /&amp;gt;$mail-&amp;gt;AddAddress(&amp;quot;SendToAddress@anydomain.com&amp;quot;); //The address you are sending mail to &amp;lt;br /&amp;gt;$mail-&amp;gt;Subject = &amp;quot;Mail Subject&amp;quot;; //Subject of the mail &amp;lt;br /&amp;gt;$mail-&amp;gt;Body = &amp;quot;Write your mail here&amp;quot;; //Body of the message&amp;lt;/div&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;You can also use account data if your server needs them for authentication:&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;div class=&amp;quot;codetop&amp;quot;&amp;gt;CODE&amp;lt;/div&amp;gt;&amp;lt;div class=&amp;quot;codemain&amp;quot;&amp;gt;$mail-&amp;gt;SMTPAuth = &amp;quot;true&amp;quot;;&amp;lt;br /&amp;gt;$mail-&amp;gt;Username = &amp;quot;User&amp;quot;;&amp;lt;br /&amp;gt;$mail-&amp;gt;Password = &amp;quot;Pwd&amp;quot;; &amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;if(!$mail-&amp;gt;Send()){ //Check for result of sending mail &amp;lt;br /&amp;gt; echo &amp;quot;There was an error sending the message&amp;quot;; //Write an error message if mail isn&amp;#039;t sent &amp;lt;br /&amp;gt; exit; //Exit the script without executing the rest of the code &amp;lt;br /&amp;gt;}&amp;lt;/div&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;To send HTML mails you just have to set:&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;div class=&amp;quot;codetop&amp;quot;&amp;gt;CODE&amp;lt;/div&amp;gt;&amp;lt;div class=&amp;quot;codemain&amp;quot;&amp;gt;$mail-&amp;gt;IsHTML(true); //You can set this parameter with a variable to let the user choose his preferred method (TEXT or HTML)&amp;lt;/div&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;Then you have to choose if you want to link images through absolute path or embedding them into the mail.&amp;lt;br /&amp;gt;Using absolute path (Ex. http://www.yourdomain.com/images/header.gif) will let you easily modify each mail you sent until read cause each mail refers to your images. This result also in a smaller file to download and won&amp;#039;t display images if the mail is read when not connected to the Internet. You can use the AltBody variable to set the message displayed if the user don&amp;#039;t display the HTML body in the message:&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;div class=&amp;quot;codetop&amp;quot;&amp;gt;CODE&amp;lt;/div&amp;gt;&amp;lt;div class=&amp;quot;codemain&amp;quot;&amp;gt;$mail-&amp;gt;AltBody = &amp;quot;You alternative text message&amp;quot;; //You have to use plain text, use \n to break line &amp;lt;/div&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;To embed images you must include some more commands in your script, using the AddEmbeddedImage function:&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;div class=&amp;quot;codetop&amp;quot;&amp;gt;CODE&amp;lt;/div&amp;gt;&amp;lt;div class=&amp;quot;codemain&amp;quot;&amp;gt;$path = &amp;quot;C:/myImages/myimage.gif&amp;quot;; //the address of the file. This could be any kind of file (sound, image, binary)&amp;lt;br /&amp;gt;$cid = &amp;quot;MyIdentifier&amp;quot;; //This is the id you must use in your HTML to include embedded files. You will not use id instead of src &amp;lt;br /&amp;gt;$name = &amp;quot;MyImage.gif&amp;quot;; //This will override your image name (OPTIONAL PARAMETER) &amp;lt;br /&amp;gt;$encoding = &amp;quot;base64&amp;quot;; //This encodes the message. Options for this are &amp;quot;8bit&amp;quot;, &amp;quot;7bit&amp;quot;, &amp;quot;binary&amp;quot;, &amp;quot;base64&amp;quot;, and &amp;quot;quoted-printable&amp;quot; (OPTIONAL PARAMETER) &amp;lt;br /&amp;gt;$type = &amp;quot;image/gif&amp;quot;; //This is MIME type of the embedded object. This parameter isn&amp;#039;t optional if you are embedding an image. You should specify his MIME type as &amp;quot;image/gif&amp;quot; or &amp;quot;image/jpeg&amp;quot;&amp;lt;br /&amp;gt;$mail-&amp;gt;AddEmbeddedImage($path,$cid,$name,$encoding,$type); //Add the specified file to the email body&amp;lt;/div&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;Repeat the code for each file you need to embed in the mail.&amp;lt;br /&amp;gt;PHPMailer has many other options you can set, like the confirm given back to a certain address:&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;div class=&amp;quot;codetop&amp;quot;&amp;gt;CODE&amp;lt;/div&amp;gt;&amp;lt;div class=&amp;quot;codemain&amp;quot;&amp;gt;$mail-&amp;gt;ConfirmReadingTo = &amp;quot;myconfirmaddress@yourdomain.com&amp;quot;; //Enter the address where you want confirms go to. &amp;lt;/div&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;or set priority of a message:&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;div class=&amp;quot;codetop&amp;quot;&amp;gt;CODE&amp;lt;/div&amp;gt;&amp;lt;div class=&amp;quot;codemain&amp;quot;&amp;gt;$mail-&amp;gt;Priority = 3; //Values are 1 = High , 3 = Normal, 5 = Low &amp;lt;/div&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;Further explaination of the commands are inside /phpdoc folder. &amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;Any comment or further examples can be addressed to info@hellord.com &amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;Hope to help&amp;lt;br /&amp;gt;Matteo Cappelloni&amp;lt;/div&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;nowiki&amp;gt;--------------------&amp;lt;/nowiki&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Riferimenti ==&lt;br /&gt;
&lt;br /&gt;
*[http://forums.emaxhosting.com/index.php?showtopic=680  PHPmailer tutorial on how to use SMTP Authentication in PHP Scripts]&lt;br /&gt;
*[http://www.hellotutorials.com/tutorials.php?id=1&lt;/div&gt;</summary>
		<author><name>Gabriele.vivinetto</name></author>
	</entry>
</feed>