Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
From the PHP mail manual mail ( string $to , string $subject , string $message , array|string $additional_headers = [] , string $additional_params = "" ) : bool PHP manual syntax (typical for...
Answer
#4: Post edited
- From the [PHP mail manual](https://www.php.net/manual/en/function.mail.php)
- > mail ( string $to , string $subject , string $message , array|string $additional_headers = [] , string $additional_params = "" ) : bool
- PHP manual syntax (typical for many languages) lists the type of each function parameter prior to the name of the parameter. Since parameters are normally passed as $variables, that syntax is used for the names, though you can use any variable names that you want, and for most (there are some occasional exceptions) PHP function parameters you can use constants as well - e.g., a "quoted string" in place of a string.
- Specifically, if a parameter is listed with a single type such as ```string``` then the parameter can only be of that type. Due to the way PHP works, using an incorrect type can result in any of:
- * Automatic "useful" conversion - e.g., numeric to string
- * Warning message
- * Error message
- * Conversion to some value that is not useful in the particular situation
- If multiple types are listed, such as ```array|string```, then each of those types is possible and they will each be handled appropriately. In the example of headers, you can either pass an array of strings or a string containing a single header or a string with multiple header strings separated by newline characters.
- An interesting twist to the usual type **in**sensitivity of PHP is the [implode function](https://www.php.net/manual/en/function.implode.php) which historically has allowed:
- ```implode ( string $separator , array $array ) : string```
- or
- ```implode ( array $array , string $separator ) : string```
- where the parameter sequence was determined by type, since the function requires exactly one array and exactly one string.
- Back to the problem at hand:
- The *message* is always, and only, a ```string```. That string can be anything from one blob of plain text to multiple sections that include HTML, plain text and attachments. More elaborate functions take all those other parts and turn them into one giant string.
- The *additional_headers* can be a string or an array. That is due to the way headers work. They are sent as a string, but they are processed as key/value pairs, each of which is handled as a string. So an array of strings works for headers. It doesn't work for messages.
- In your example, just put it all together as one string.
- $message = "Name: " . $_POST["name"] . "\r\n"
- . "Email: " . $_POST["email"] . "\r\n"
- . "Phone: " . $_POST["phone"] . "\r\n"
- . "Topic: " . $_POST["topic"] . "\r\n"
- . "Date: " . $_POST["date"] . "\r\n"
- . "Time: " . $_POST["time"] . "\r\n"
- . "Notes: " . $_POST["notes"] . "\r\n";
- From the [PHP mail manual](https://www.php.net/manual/en/function.mail.php)
- > mail ( string $to , string $subject , string $message , array|string $additional_headers = [] , string $additional_params = "" ) : bool
- PHP manual syntax (typical for many languages) lists the type of each function parameter prior to the name of the parameter. Since parameters are normally passed as $variables, that syntax is used for the names, though you can use any variable names that you want, and for most (there are some occasional exceptions) PHP function parameters you can use constants as well - e.g., a "quoted string" in place of a string.
- Specifically, if a parameter is listed with a single type such as ```string``` then the parameter can only be of that type. Due to the way PHP works, using an incorrect type can result in any of:
- * Automatic "useful" conversion - e.g., numeric to string
- * Warning message
- * Error message
- * Conversion to some value that is not useful in the particular situation
- If multiple types are listed, such as ```array|string```, then each of those types is possible and they will each be handled appropriately. In the example of headers, you can either pass an array of strings or a string containing a single header or a string with multiple header strings separated by newline characters.
- An interesting twist to the usual type **in**sensitivity of PHP is the [implode function](https://www.php.net/manual/en/function.implode.php) which historically has allowed:
- ```implode ( string $separator , array $array ) : string```
- or
- ```implode ( array $array , string $separator ) : string```
- where the parameter sequence was determined by type, since the function requires exactly one array and exactly one string.
- Back to the problem at hand:
- The *message* is always, and only, a ```string```. That string can be anything from one blob of plain text to multiple sections that include HTML, plain text and attachments. More elaborate functions take all those other parts and turn them into one giant string.
- The *additional_headers* can be a string or an array. That is due to the way headers work. They are sent as a string, but they are processed as key/value pairs, each of which is handled as a string. So an array of strings works for headers. It doesn't work for messages.
- In your example, just put it all together as one string.
- $message = "Name: " . $_POST["name"] . "\r\n"
- . "Email: " . $_POST["email"] . "\r\n"
- . "Phone: " . $_POST["phone"] . "\r\n"
- . "Topic: " . $_POST["topic"] . "\r\n"
- . "Date: " . $_POST["date"] . "\r\n"
- . "Time: " . $_POST["time"] . "\r\n"
- . "Notes: " . $_POST["notes"] . "\r\n";
#3: Post edited
- From the [PHP mail manual](https://www.php.net/manual/en/function.mail.php)
- > mail ( string $to , string $subject , string $message , array|string $additional_headers = [] , string $additional_params = "" ) : bool
The *message* is always, and only, a string. That string can be anything from one blob of plain text to multiple sections that include HTML, plain text and attachments. More elaborate functions take all those other parts and turn them into one giant string.- The *additional_headers* can be a string or an array. That is due to the way headers work. They are sent as a string, but they are processed as key/value pairs, each of which is handled as a string. So an array of strings works for headers. It doesn't work for messages.
- In your example, just put it all together as one string.
- $message = "Name: " . $_POST["name"] . "\r\n"
- . "Email: " . $_POST["email"] . "\r\n"
- . "Phone: " . $_POST["phone"] . "\r\n"
- . "Topic: " . $_POST["topic"] . "\r\n"
- . "Date: " . $_POST["date"] . "\r\n"
- . "Time: " . $_POST["time"] . "\r\n"
- . "Notes: " . $_POST["notes"] . "\r\n";
- From the [PHP mail manual](https://www.php.net/manual/en/function.mail.php)
- > mail ( string $to , string $subject , string $message , array|string $additional_headers = [] , string $additional_params = "" ) : bool
- PHP manual syntax (typical for many languages) lists the type of each function parameter prior to the name of the parameter. Since parameters are normally passed as $variables, that syntax is used for the names, though you can use any variable names that you want, and for most (there are some occasional exceptions) PHP function parameters you can use constants as well - e.g., a "quoted string" in place of a string.
- Specifically, if a parameter is listed with a single type such as ```string``` then the parameter can only be of that type. Due to the way PHP works, using an incorrect type can result in any of:
- * Automatic "useful" conversion - e.g., numeric to string
- * Warning message
- * Error message
- * Conversion to some value that is not useful in the particular situation
- If multiple types are listed, such as ```array|string```, then each of those types is possible and they will each be handled appropriately. In the example of headers, you can either pass an array of strings or a string containing a single header or a string with multiple header strings separated by newline characters.
- An interesting twist to the usual type **in**sensitivity of PHP is the [implode function](https://www.php.net/manual/en/function.implode.php) which historically has allowed:
- ```implode ( string $separator , array $array ) : string```
- or
- ```implode ( array $array , string $separator ) : string```
- where the parameter sequence was determined by type, since the function requires exactly one array and exactly one string.
- Back to the problem at hand:
- The *message* is always, and only, a ```string```. That string can be anything from one blob of plain text to multiple sections that include HTML, plain text and attachments. More elaborate functions take all those other parts and turn them into one giant string.
- The *additional_headers* can be a string or an array. That is due to the way headers work. They are sent as a string, but they are processed as key/value pairs, each of which is handled as a string. So an array of strings works for headers. It doesn't work for messages.
- In your example, just put it all together as one string.
- $message = "Name: " . $_POST["name"] . "\r\n"
- . "Email: " . $_POST["email"] . "\r\n"
- . "Phone: " . $_POST["phone"] . "\r\n"
- . "Topic: " . $_POST["topic"] . "\r\n"
- . "Date: " . $_POST["date"] . "\r\n"
- . "Time: " . $_POST["time"] . "\r\n"
- . "Notes: " . $_POST["notes"] . "\r\n";
#2: Post edited
RTFM:[PHP mail manual](https://www.php.net/manual/en/function.mail.php)- > mail ( string $to , string $subject , string $message , array|string $additional_headers = [] , string $additional_params = "" ) : bool
- The *message* is always, and only, a string. That string can be anything from one blob of plain text to multiple sections that include HTML, plain text and attachments. More elaborate functions take all those other parts and turn them into one giant string.
The *additional_headers* can be a string or an array. That is due to the way headers work. They are sent as a string, but they are processed as key/value pairs, each of which is handled as a string. So an array of strings works for headers. It doesn't work for message.- In your example, just put it all together as one string.
- $message = "Name: " . $_POST["name"] . "\r\n"
- . "Email: " . $_POST["email"] . "\r\n"
- . "Phone: " . $_POST["phone"] . "\r\n"
- . "Topic: " . $_POST["topic"] . "\r\n"
- . "Date: " . $_POST["date"] . "\r\n"
- . "Time: " . $_POST["time"] . "\r\n"
- . "Notes: " . $_POST["notes"] . "\r\n";
- From the [PHP mail manual](https://www.php.net/manual/en/function.mail.php)
- > mail ( string $to , string $subject , string $message , array|string $additional_headers = [] , string $additional_params = "" ) : bool
- The *message* is always, and only, a string. That string can be anything from one blob of plain text to multiple sections that include HTML, plain text and attachments. More elaborate functions take all those other parts and turn them into one giant string.
- The *additional_headers* can be a string or an array. That is due to the way headers work. They are sent as a string, but they are processed as key/value pairs, each of which is handled as a string. So an array of strings works for headers. It doesn't work for messages.
- In your example, just put it all together as one string.
- $message = "Name: " . $_POST["name"] . "\r\n"
- . "Email: " . $_POST["email"] . "\r\n"
- . "Phone: " . $_POST["phone"] . "\r\n"
- . "Topic: " . $_POST["topic"] . "\r\n"
- . "Date: " . $_POST["date"] . "\r\n"
- . "Time: " . $_POST["time"] . "\r\n"
- . "Notes: " . $_POST["notes"] . "\r\n";
#1: Initial revision
RTFM: [PHP mail manual](https://www.php.net/manual/en/function.mail.php) > mail ( string $to , string $subject , string $message , array|string $additional_headers = [] , string $additional_params = "" ) : bool The *message* is always, and only, a string. That string can be anything from one blob of plain text to multiple sections that include HTML, plain text and attachments. More elaborate functions take all those other parts and turn them into one giant string. The *additional_headers* can be a string or an array. That is due to the way headers work. They are sent as a string, but they are processed as key/value pairs, each of which is handled as a string. So an array of strings works for headers. It doesn't work for message. In your example, just put it all together as one string. $message = "Name: " . $_POST["name"] . "\r\n" . "Email: " . $_POST["email"] . "\r\n" . "Phone: " . $_POST["phone"] . "\r\n" . "Topic: " . $_POST["topic"] . "\r\n" . "Date: " . $_POST["date"] . "\r\n" . "Time: " . $_POST["time"] . "\r\n" . "Notes: " . $_POST["notes"] . "\r\n";