Home > Article > Backend Development > Send email with php (method 1)_PHP tutorial
[html]
1. Example:
[html]
1. $content ="ceshi";
2. $technicalemail="www.2cto.com";
3. $headers = "From: =?utf-8?B?".base64_encode('chenglong')."?= <$technicalemail>rn";
4.
5. $content = strip_tags($content);
6. $a = @mail($technicalemail,'=?utf-8?B?'.base64_encode('Error submitted').'?=',$content,$headers);
7. if($a)
8. {
9. echo 'Email sent successfully! ';
10. }
Send via mail() function:
1. Need to configure php.ini email information
Open the php.ini configuration file and configure the red position
; For Win32 only.
SMTP = localhost --- If sendmail is installed on this machine, this means using the local mail server, which can also be an IP address, and the server domain name
smtp_port = 25 smtp_port =
; For Win32 only.
;sendmail_from = www.2cto.com ---Writable or not Remove the semicolon here
; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
;sendmail_path =
2.mail() function
The mail() function allows sending emails directly from scripts
The mail() function returns a boolean value. It returns true if successful and false
on failure.
mail(to,subject,message,headers,paeameters);
to --Required, specifies the recipient of the email
subject – required, specifies the subject of the email, this parameter cannot contain any newline characters
message --Required, specifies the message to be sent
headers --optional, specifies additional headers, such as from, Cc and Bcc. You can refer to some information
Parameters --optional, specifies additional parameters for the sendmail program
3. In php.ini, remove the ";" in front of extension=php_imap.dll
Author: Vericlongmore