We know that
PHP Swift code example for sending emails:
- <? Php
- Include_once ("Swift. php ");
- Include_once ("Swift/Connection/SMTP. php ");
- Include_once ("Swift/Authenticator/LOGIN. php ");
- // Recipient's address
- $ Receive_mail = "demo_receive@gmail.com ";
- // Create an smtp connection. The smtp address and port used to send emails
- $ Smtp = new Swift_Connection_SMTP
('Smtp .sina.com ', 25 );
- // Set the email account used to send emails
- $ Smtp-> setUsername ('demo _ send@sina.com ');
- // Set the logon password of the sender's email address
- $ Smtp-> setPassword ('1qaz2wsx ');
- // Add ssl connection support. If this option is not enabled, it is sent to gmail.
If this option is enabled, the mailbox that requires an ssl connection will fail.
The email sending speed will be affected.
- If (stripos ($ receive_mail, "@ gmail.com ")! = False ){
- $ Smtp-> attachAuthenticator (new
Swift_Authenticator_LOGIN ());
- }
- $ Swift = new Swift ($ smtp );
- // Mail title
- $ Title = "you have received a new resume for applying for a job as a php programmer ";
- // Body of the email
- $ Content = "Postmaster, hello! You have received a new resume,
Apply for a job as a php programmer... <br/> ";
- $ Message = new Swift_Message
($ Title, $ content, 'text/html ', 'base64 ');
- Echo ($ swift-> send ($ message,
$ Receive_mail, new Swift_Address
('Demo _ send@sina.com ', 'demo _ sender ')))
? 'Success': 'failed ';
- ?>
We hope that the above PHP Swift usage will be helpful to friends who need it.