1 / 11

Correio Electrónico PHP Send()

Correio Electrónico PHP Send(). A função send (). Para enviar correio electrónico através do PHP precisamos de utilizar a função: send () Sintaxe: bool mail ( string $to , string $subject , string $message [, string $ additional_headers [, string $ additional_parameters ]] ).

dexter-neal
Download Presentation

Correio Electrónico PHP Send()

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Correio Electrónico PHPSend()

  2. A função send() • Para enviar correio electrónico através do PHP precisamos de utilizar a função: send() • Sintaxe: • boolmail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )

  3. A função send() boolmail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] ) • $to – variávelquevaiarmazenar o valor do endereçoparaondevai o mail • $subject – variávelquearmazena o assunto do mail • $message – variavélquecontém a mensagemprópriamentedita

  4. A função send() $additional_headers – Cabeçalhosespeciaoscasoenviar o correioelectronicoemformato HTML: //para o envio em formato HTML $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html;charset=iso-8859-1\r\n"; //endereço do remetente $headers .= "From: LanaPT <webmaster@lanapt.com>\r\n"; //endereço de resposta, se queremos que seja diferente a do remetente $headers .= "Reply-To: webmaster@lanapt.com\r\n“;

  5. A função Send() //endereços que receberão uma copia $headers .= "Cc: lana@net.sapo.pt\r\n"; //endereços que receberão uma copia oculta$headers .= "Bcc: webmaster@turma25.com,dbk@gmail.com\r\n"; $additional_parameters – Parametrosadicionais (flags especiais)

  6. Exemplo 1 <?php// mensagem$mensagem = ”linha1\nlinha2\nlinha 3";// No caso das linhas ultrapassarem os 70 caracteres utliliza-se a função wordwrap()$mensagem = wordwrap($mensagem, 70);// Sendmail(‘ola@example.com', ‘O meu assunto',$mensagem); ?>

  7. Exemplo 2 - HTML • <?php$to =‘ola@example.com';$subject = ‘Assunto';$message = ‘Com estás?';$headers = 'From: webmaster@lanapt.com' . "\r\n" .    'Reply-To: webmaster@lanapt.com' . "\r\n" .    'X-Mailer: PHP/' . phpversion();mail($to, $subject, $message, $headers);?>

  8. NOTA A mensagem pode conter código HTML: $mensagem=‘<html><head></head> <body> Codificação em HTML </body> </html>’; // Para enviaresteemail emHTML tem de se enviar no header oContent-type:$headers  = 'MIME-Version: 1.0' . "\r\n";$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

  9. Exemplo de Form de Contacto • Ficheiro contacto.php: • <?php $to = “suporte@eliezer.com"; $subject = "Contacto"; $email = $_REQUEST['email'] ; $message = $_REQUEST['mensagem'] ; $headers = "From: $email"; $sent = mail($to, $subject, $message, $headers) ; if($sent) {print “O email foienviado com sucesso"; } else {print “Houve um erro no envio do email"; }?>

  10. Exemplo Form de Contacto • Página onde está o formulario de contacto: • <formmethod="post" action="contacto.php"> Email: <input name="email" type="text"><br>Mensagem:<br> <textareaname="mensagem" rows="15" cols="40"></textarea><br> <input type="submit"> </form>

  11. Exercício de aplicação

More Related