Php mail sending method with CC and BCC

Source: Internet
Author: User

Php mail sending method with CC and BCC

This article describes how to send php mail with CC and BCC. It involves the use of the mail function in php and is very useful. For more information, see

 

 

This example describes how to send php mail with CC and BCC. Share it with you for your reference. The specific analysis is as follows:

The mail function of php is used in the program. The function is defined as follows:
Bool mail (string $ to, string $ subject, string $ message [, string $ additional_headers [, string $ additional_parameters])
Returns True if the email is successfully sent; otherwise, returns False.

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

<Html>

<Head>

<Title> Send email with CC and BCC </title>

</Head>

<Body>

<Form action = "sendemail. php" method = post name = form1>

<Table>

<Tbody>

<Tr>

<Td>

<Div align = right> <B> To </B> </div> </td>

<Td>

<P> Name <input name = mailtoname size = 35> <br/> email

<Input name = mailtomail size = 35> </p> </td> </tr>

<Tr>

<Td>

<Div align = right> <B> CC </B> </div> </td>

<Td> <input name = mailcc size = 35> </td> </tr>

<Tr>

<Td>

<Div align = right> <B> BCC </B> </div> </td>

<Td> <input name = mailbcc size = 35> </td> </tr>

<Tr>

<Td>

<Div align = right> <B> Priority </B> </div> </td>

<Td> <select name = mailpriority>

<Option value = 1> Highest </option>

<Option value = 2> High </option>

<Option selected value = 3> Normal </option>

<Option value = 4> Low </option>

<Option value = 5> Lowest </option>

</Select>

</Td> </tr>

<Tr>

<Td> <div align = right> <B> Subject </B> </div> </td>

<Td> <input name = mailsubject size = 35> </td> </tr>

<Tr>

<Td>

<Div align = right> <B> Message </B> </div> </td>

<Td> <textarea cols = 50 name = mailbody rows = 7> </textarea> </td> </tr>

<Tr>

<Td colSpan = 2>

<Div align = center>

<Input name = Submit type = submit value = Submit> </div>

</Td>

</Tr>

</Tbody>

</Table>

</Form>

</Body>

</Html>

Backend php code, saved as sendmail. php

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

<Html>

<Head>

<Title> Send Mail Script </title>

</Head>

<Body>

<? Php

$ Message = "";

If (empty ($ mailtoname) | empty ($ mailtomail )){

Die ("Recipient is blank! ");

} Else {

$ To = $ mailtoname. "<". $ mailtomail. "> ";

}

If (empty ($ mailsubject )){

$ Mailsubject = "";

}

If ($ mailpriority> 0) & ($ mailpriority <6 )){

$ Mailheader = "X-Priority:". $ mailpriority. "\ n ";

}

$ Mailheader. = "From:". "Sales Team <sales@yourdomain.com> \ n ";

$ Mailheader. = "X-Sender:". "support@yourdomain.com \ n ";

$ Mailheader. = "Return-Path:". "support@yourdomain.com \ n ";

If (! Empty ($ mailcc )){

$ Mailheader. = "Cc:". $ mailcc. "\ n ";

}

If (! Empty ($ mailbcc )){

$ Mailheader. = "Bcc:". $ mailbcc. "\ n ";

}

If (empty ($ mailbody )){

$ Mailbody = "";

}

$ Result = mail ($ to, $ mailsubject, $ mailbody, $ mailheader );

Echo "<center> <B> Mail sent to". "$ to". "<br/> ";

Echo $ mailsubject. "<br/> ";

Echo $ mailbody. "<br/> ";

Echo $ mailheader. "<br/> ";

If ($ result ){

Echo "<p> <B> Email sent successfully! </B> </p> ";

} Else {

Echo "<p> <B> Email cocould not be sent. </B> </p> ";

}

?>

<Div align = "center">

<Table> <tr> <td width = "66"> <div align = "right"> <B> To </B> </div> </td>

<Td width = "308" type = "codeph" text = "codeph"> <B>

<? Php echo $ mailtoname. "[". $ mailtomail. "]";?>

</B> </td> </tr>

<Tr> <td width = "66"> <div align = "right"> <B> CC </B> </div> </td>

<Td width = "308"> <B> <? Php echo $ mailcc;?> </B> </td> </tr>

<Tr> <td width = "66"> <div align = "right"> <B> BCC </B> </div> </td>

<Td width = "308"> <B> <? Php echo $ mailbcc;?> </B> </td> </tr>

<Tr> <td width = "66"> <div align = "right"> <B> Priority </B> </div> </td>

<Td width = "308"> <B> <? Php echo $ mailpriority;?> </B> </td> </tr>

<Tr> <td width = "66"> <div align = "right"> <B> Subject </B> </div> </td>

<Td width = "308"> <B> <? Php echo $ mailsubject;?> </B> </td> </tr>

<Tr> <td width = "66"> <div align = "right"> <B> Message </B> </div> </td>

<Td width = "308"> <B> <? Php echo $ mailbody;?> </B> </td> </tr>

</Table>

</Div>

</Body>

</Html>

I hope this article will help you with php programming.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.