Penggunaan fungsi WINDOWS+R pada PHP

Berbagai macam kombinasi keyboard sebenarnya ada tetapi jarang diketahui oleh banyak orang, sebenarnya fungsi kombinasi keyboard ini cukup bermanfaat untuk mempercepat kerja (shortcut) dengan memangkas beberapa langkah menjadi satu langkah saja, beberapa kumpulan informasi kombinasi dan fungsi pada keyboard.

Show
  • Ctrl + A - Memilih semua huruf
  • Ctrl + B - Menebalkan Huruf yang terpilih (Bold).
  • Ctrl + C - Menyalin/menggandakan (Copy).
  • Ctrl + D - Memilih Jenis Huruf (Font).
  • Ctrl + E - Perataan tengah (Center).
  • Ctrl + F - Temukan Kalimat/Huruf (Find).
  • Ctrl + G - Pergi ke (go to).
  • Ctrl + H - Temukan Kalimat dan Tindih (Find and Replace).
  • Ctrl + I - Membuat cetak miring (Italic).
  • Ctrl + J - Membuat rata kiri kanan/seimbang (Justify).
  • Ctrl + K - Memasukkan Alamat tautan (Insert Hyperlink).
  • Ctrl + L - Membuat teks rata kiri (Left).
  • Windows + L - mengunci layar komputer/laptop
  • Ctrl + M - Menggeser penempatan paragraf ke kanan.
  • Ctrl + Shift + M - Menggeser penempatan paragraf ke kiri.
  • Ctrl + N - Membuat berkas baru (New).
  • Ctrl + O - Membuka berkas (Open).
  • Ctrl (prints).
  • Ctrl + Q - Menghapus pengaturan yang telah dibuat.
  • Ctrl + R - Membuat rata kanan (Right).
  • Ctrl + S - Simpan (Save).
  • F12 - Menyimpan kembali dengan nama yang sama atau berbeda (save as).
  • Ctrl + T - Menggeser tabulasi bawah ke kanan.
  • Ctrl + Shift + T - Menggeser tabulasi bagian bawah ke kiri.
  • Ctrl + U - Membuat garis bawah (Underline).
  • Ctrl + V - Tempel (Paste).
  • Ctrl + W - Keluar dari berkas.
  • Ctrl + X - Potong (Cut).
  • Ctrl + Y - Mengembelikan perintah yang telah dibatalkan undo (Redo.
  • Ctrl + Z - Membatalkan perintah sebelumnya (Undo)

Sedangkan tombol function(F) pada keyboard

• F1 :

  • Hampir selalu digunakan sebagai bantuan tombol, hampir setiap program ini akan membantu

membuka layar saat ini tombol yang ditekan.

  • Windows Key + F1 akan membuka Microsoft Windows pusat bantuan dan dukungan.
  • Buka Task Pane.

• F2:

  • Dalam Windows umumnya digunakan untuk mengubah nama yang disorot atau file icon.
  • Ctrl + Alt + F2 untuk membuka dokumen baru dalam Microsoft Word.
  • Ctrl + F2 menampilkan pratinjau cetak jendela Microsoft Word.

• F3:

  • Seringkali membuka fitur pencarian untuk berbagai program termasuk Microsoft Windows.
  • Shift + F3 akan mengubah teks dalam Microsoft Word dari atas ke bawah kasus atau huruf

besar pada awal setiap kata. • F4:

  • Terbuka menemukan jendela.
  • Ulangi terakhir dilakukan tindakan (Word 2000 +)
  • Alt + F4 akan menutup program sedang aktif di Microsoft Windows.
  • Ctrl + F4 akan menutup jendela yang terbuka di jendela yang sedang aktif dalam Microsoft Windows.

• F5:

  • Dalam semua modern browser Internet akan menekan F5 refresh atau reload halaman

atau dokumen jendela.

  • Buka menemukan, mengganti, dan pergi ke jendela Microsoft Word.
  • Mulai tayangan slide dalam PowerPoint.

• F6:

  • Pindahkan kursor ke Address bar di Internet Explorer dan Mozilla Firefox.
  • Ctrl + Shift + F6 terbuka buka ke dokumen Microsoft Word.

• F7:

  • Biasanya digunakan untuk periksa ejaan serta gramatika memeriksa dokumen

Microsoft dalam program seperti Microsoft Word, Outlook, dll

  • Shift + F7 menjalankan Thesaurus memeriksa pada kata disorot.
  • Ternyata pada sisipan browsing di Mozilla Firefox.

• F8: Fungsi tombol * untuk memasukkan Windows startup menu, biasanya digunakan untuk masuk ke Windows Safe Mode. • F9:

  • Pengukuran yang Membuka toolbar dalam Quark 5.0.

• F10:

  • Pada Microsoft Windows mengaktifkan menu bar di aplikasi yang terbuka.
  • Shift + F10 sama kanan pada icon yang disorot, file, atau link Internet.

• F11: * Modus layar penuh dalam semua modern browser Internet.

• F12:* Buka Simpan sebagai jendela Microsoft Word.

  • Shift + F12 menyimpan dokumen Microsoft Word.
  • Ctrl + Shift + F12 mencetak dokumen Microsoft Word.

"Semoga bermanfaat"

(PHP 4, PHP 5, PHP 7, PHP 8)

mailSend mail

Description

mail(
    string $to,
    string $subject,
    string $message,
    array|string $additional_headers = [],
    string $additional_params = ""
): bool

Parameters

to

Receiver, or receivers of the mail.

The formatting of this string must comply with » RFC 2822. Some examples are:

  • , another
  • User <>
  • User <>, Another User
subject

Subject of the email to be sent.

message

Message to be sent.

Each line should be separated with a CRLF (\r\n). Lines should not be larger than 70 characters.

Caution

(Windows only) When PHP is talking to a SMTP server directly, if a full stop is found on the start of a line, it is removed. To counter-act this, replace these occurrences with a double dot.

$text str_replace("\n.""\n.."$text);
?>

additional_headers (optional)

String or array to be inserted at the end of the email header.

This is typically used to add extra headers (From, Cc, and Bcc). Multiple extra headers should be separated with a CRLF (\r\n). If outside data are used to compose this header, the data should be sanitized so that no unwanted headers could be injected.

If an array is passed, its keys are the header names and its values are the respective header values.

Note:

Before PHP 5.4.42 and 5.5.27, repectively, additional_headers did not have mail header injection protection. Therefore, users must make sure specified headers are safe and contains headers only. i.e. Never start mail body by putting multiple newlines.

Note:

When sending mail, the mail must contain a From header. This can be set with the additional_headers parameter, or a default can be set in php.ini.

Failing to do this will result in an error message similar to Warning: mail(): "sendmail_from" not set in php.ini or custom "From:" header missing. The From header sets also Return-Path when sending directly via SMTP (Windows only).

Note:

If messages are not received, try using a LF (\n) only. Some Unix mail transfer agents (most notably » qmail) replace LF by CRLF automatically (which leads to doubling CR if CRLF is used). This should be a last resort, as it does not comply with » RFC 2822.

additional_params (optional)

The additional_params parameter can be used to pass additional flags as command line options to the program configured to be used when sending mail, as defined by the sendmail_path configuration setting. For example, this can be used to set the envelope sender address when using sendmail with the -f sendmail option.

This parameter is escaped by escapeshellcmd() internally to prevent command execution. escapeshellcmd() prevents command execution, but allows to add additional parameters. For security reasons, it is recommended for the user to sanitize this parameter to avoid adding unwanted parameters to the shell command.

Since escapeshellcmd() is applied automatically, some characters that are allowed as email addresses by internet RFCs cannot be used. mail() can not allow such characters, so in programs where the use of such characters is required, alternative means of sending emails (such as using a framework or a library) is recommended.

The user that the webserver runs as should be added as a trusted user to the sendmail configuration to prevent a 'X-Warning' header from being added to the message when the envelope sender (-f) is set using this method. For sendmail users, this file is /etc/mail/trusted-users.

Return Values

Returns true if the mail was successfully accepted for delivery, false otherwise.

It is important to note that just because the mail was accepted for delivery, it does NOT mean the mail will actually reach the intended destination.

Changelog

VersionDescription
7.2.0 The additional_headers parameter now also accepts an array.

Examples

Example #1 Sending mail.

Using mail() to send a simple email:

// The message
$message "Line 1\r\nLine 2\r\nLine 3";// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message wordwrap($message70"\r\n");// Send
mail('''My Subject'$message);
?>

Example #2 Sending mail with extra headers.

The addition of basic headers, telling the MUA the From and Reply-To addresses:

$to      '';
$subject 'the subject';
$message 'hello';
$headers 'From: ' "\r\n" .
    
'Reply-To: ' "\r\n" .
    
'X-Mailer: PHP/' phpversion();mail($to$subject$message$headers);
?>

Example #3 Sending mail with extra headers as array

This example sends the same mail as the example immediately above, but passes the additional headers as array (available as of PHP 7.2.0).

$to      '';
$subject 'the subject';
$message 'hello';
$headers = array(
    
'From' => '',
    
'Reply-To' => '',
    
'X-Mailer' => 'PHP/' phpversion()
);
mail($to$subject$message$headers);
?>

Example #4 Sending mail with an additional command line parameter.

The additional_params parameter can be used to pass an additional parameter to the program configured to use when sending mail using the sendmail_path.

mail('''the subject''the message'null,
   
'-f');
?>

Example #5 Sending HTML email

It is also possible to send HTML email with mail().

// Multiple recipients
$to ', '// note the comma

// Subject

$subject 'Birthday Reminders for August';// Message
$message '


  Birthday Reminders for August


  

Here are the birthdays upcoming in August!


  
    
      
    
    
      
    
    
      
    
  
PersonDayMonthYear
Johny10thAugust1970
Sally17thAugust1973



'
;// To send HTML mail, the Content-type header must be set
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: text/html; charset=iso-8859-1';// Additional headers
$headers[] = 'To: Mary <>, Kelly <>';
$headers[] = 'From: Birthday Reminder <>';
$headers[] = 'Cc: ';
$headers[] = 'Bcc: ';// Mail it
mail($to$subject$messageimplode("\r\n"$headers));
?>

Note:

If intending to send HTML or otherwise Complex mails, it is recommended to use the PEAR package » PEAR::Mail_Mime.

Notes

Note:

The SMTP implementation (Windows only) of mail() differs in many ways from the sendmail implementation. First, it doesn't use a local binary for composing messages but only operates on direct sockets which means a MTA is needed listening on a network socket (which can either on the localhost or a remote machine).

Second, the custom headers like From:, Cc:, Bcc: and Date: are not interpreted by the MTA in the first place, but are parsed by PHP.

As such, the to parameter should not be an address in the form of "Something <>". The mail command may not parse this properly while talking with the MTA.

Note:

It is worth noting that the mail() function is not suitable for larger volumes of email in a loop. This function opens and closes an SMTP socket for each email, which is not very efficient.

For the sending of large amounts of email, see the » PEAR::Mail, and » PEAR::Mail_Queue packages.

Note:

The following RFCs may be useful: » RFC 1896, » RFC 2045, » RFC 2046, » RFC 2047, » RFC 2048, » RFC 2049, and » RFC 2822.

See Also

  • mb_send_mail() - Send encoded mail
  • imap_mail() - Send an email message
  • » PEAR::Mail
  • » PEAR::Mail_Mime

Anonymous

2 years ago

If you notice wrong displayed characters in the email it's because you need to properly set the Content-Type and the Charset in the headers of the email:

$headers = 'Content-Type: text/plain; charset=utf-8' . "\r\n";
?>

Mostly, UTF-8 is your best choice.

You can set custom headers with the fourth parameter of the mail() function.

To make the whole thing waterproof, add the following header too:

$headers .= 'Content-Transfer-Encoding: base64' . "\r\n";
?>

Now you can use the combination of UTF-8 and Base64 to properly encode the subject line and the recipient name like this:

$subject = '=?UTF-8?B?' . base64_encode('Test email with German Umlauts öäüß') . '?=';
$recipient = '=?UTF-8?B?' . base64_encode('Margret Müller') . '?= <>';
?>

And don't forget to Base64 encode the email message too:

$message = base64_encode('This email contains German Umlauts öäüß.');
?>

All references are taken from:
https://dev.to/lutvit/how-to-make-the-php-mail-function-awesome-3cii

Anonymous

5 years ago

Security advice: Although it is not documented, for the parameters $to and $subject the mail() function changes at least \r and \n to space. So these parameters are safe against injection of additional headers. But you might want to check $to for commas as these separate multiple addresses and you might not want to send to more than one recipient.

The crucial part is the $additional_headers parameter. This parameter can't be cleaned by the mail() function. So it is up to you to prevent unwanted \r or \n to be inserted into the values you put in there. Otherwise you just created a potential spam distributor.

php at simoneast dot net

5 years ago

Often it's helpful to find the exact error message that is triggered by the mail() function. While the function doesn't provide an error directly, you can use error_get_last() when mail() returns false.

$success = mail('', 'My Subject', $message);
if (!
$success) {
   
$errorMessage = error_get_last()['message'];
}
?>

(Tested successfully on Windows which uses SMTP by default, but sendmail on Linux/OSX may not provide the same level of detail.)

Thanks to https://stackoverflow.com/a/20203870/195835

charles dot fisher at arconic dot com

4 years ago

I migrated an application to a platform without a local transport agent (MTA). I did not want to configure an MTA, so I wrote this xxmail function to replace mail() with calls to a remote SMTP server. Hopefully it is of some use.

function xxmail($to, $subject, $body, $headers)
{
$smtp = stream_socket_client('tcp://smtp.yourmail.com:25', $eno, $estr, 30);

$B = 8192;
$c = "\r\n";
$s = '';

fwrite($smtp, 'helo ' . $_ENV['HOSTNAME'] . $c);
  $junk = fgets($smtp, $B);

// Envelope
fwrite($smtp, 'mail from: ' . $s . $c);
  $junk = fgets($smtp, $B);
fwrite($smtp, 'rcpt to: ' . $to . $c);
  $junk = fgets($smtp, $B);
fwrite($smtp, 'data' . $c);
  $junk = fgets($smtp, $B);

// Header
fwrite($smtp, 'To: ' . $to . $c);
if(strlen($subject)) fwrite($smtp, 'Subject: ' . $subject . $c);
if(strlen($headers)) fwrite($smtp, $headers); // Must be \r\n (delimited)
fwrite($smtp, $headers . $c);

// Body
if(strlen($body)) fwrite($smtp, $body . $c);
fwrite($smtp, $c . '.' . $c);
  $junk = fgets($smtp, $B);

// Close
fwrite($smtp, 'quit' . $c);
  $junk = fgets($smtp, $B);
fclose($smtp);
}

pangz dot lab at gmail dot com

2 years ago

* Sending email with attachment

function sendMail(
    string $fileAttachment,
    string $mailMessage = MAIL_CONF["mailMessage"],
    string $subject     = MAIL_CONF["subject"],
    string $toAddress   = MAIL_CONF["toAddress"],
    string $fromMail    = MAIL_CONF["fromMail"]
): bool {

        $fileAttachment = trim($fileAttachment);
    $from           = $fromMail;
    $pathInfo       = pathinfo($fileAttachment);
    $attchmentName  = "attachment_".date("YmdHms").(
    (isset($pathInfo['extension']))? ".".$pathInfo['extension'] : ""
    );

        $attachment    = chunk_split(base64_encode(file_get_contents($fileAttachment)));
    $boundary      = "PHP-mixed-".md5(time());
    $boundWithPre  = "\n--".$boundary;

        $headers   = "From: $from";
    $headers  .= "\nReply-To: $from";
    $headers  .= "\nContent-Type: multipart/mixed; boundary=\"".$boundary."\"";

        $message   = $boundWithPre;
    $message  .= "\n Content-Type: text/plain; charset=UTF-8\n";
    $message  .= "\n $mailMessage";

        $message .= $boundWithPre;
    $message .= "\nContent-Type: application/octet-stream; name=\"".$attchmentName."\"";
    $message .= "\nContent-Transfer-Encoding: base64\n";
    $message .= "\nContent-Disposition: attachment\n";
    $message .= $attachment;
    $message .= $boundWithPre."--";

        return mail($toAddress, $subject, $message, $headers);
}

* Sending email in html

function sendHtmlMail(
    string $mailMessage = MAIL_CONF["mailMessage"],
    string $subject     = MAIL_CONF["subject"],
    array $toAddress    = MAIL_CONF["toAddress"],
    string $fromMail    = MAIL_CONF["fromMail"]
): bool {

        $to        = implode(",", $toAddress);
    $headers[] = 'MIME-Version: 1.0';
    $headers[] = 'Content-type: text/html; charset=iso-8859-1';   
    $headers[] = 'To: '.$to;
    $headers[] = 'From: '.$fromMail;

    return mail($to, $subject, $mailMessage, implode("\r\n", $headers));
}

ABOMB

10 years ago

I was having delivery issues from this function to Gmail, Yahoo, AOL, etc.  I used the notes here to figure that you need to be setting your Return-Path to a valid email to catch bounces.  There are two extra delivery gotchas on top of that:

1) The domain in the email used in the -f option in the php.ini sendmail parameter or in the mail() extra parameters field, needs to have a valid SPF record for the domain (in DNS as a "TXT" record type for sure and add an additional  "SPF" type record if possible).  Why? That's header field being used for spam checks.

2) You should also use a domain key or DKIM.  The trick here is that the domain key/DKIM is case sensitive!  I used Cpanel to create my domain key which automatically used all lowercase domain names in the key creation.  I found when  sending email and using a camel case "-f " option, my key was not accepted.  However it was accepted when I used "-f ".

There are many other factors that can contribute to mail not getting to inboxes, including your own multiple failed testing attempts, so I suggest you consult each site's guidelines and don't ask me for help.  These are just the couple technical issues that helped my case.

I hope this saves someone some time and headaches...

chris at ocproducts dot com

5 years ago

The 'sendmail' executable which PHP uses on Linux/Mac (not Windows) expects "\n" as a line separator.

This executable is a standard, and emulated by other MTAs.

"\n" is confirmed required for qmail and postfix, probably also for sendmail and exim but I have not tested.

If you pass through using "\r\n" as a separator it may appear to work, but your email will be subtly corrupted and some middleware may break. It only works because some systems will clean up your mistake.

If you are implementing DKIM be very careful, as DKIM checks will fail (at least on popular validation tools) if you screw this up. DKIM must be calculated using "\r\n" but then you must switch it all to "\n" when using the PHP mail function.

On Windows, however, you should use "\r\n" because PHP is using SMTP in this situation, and hence the normal rules of the SMTP protocol (not the normal rules of Unix piping) apply.

Ben Cooke

16 years ago

Note that there is a big difference between the behavior of this function on Windows systems vs. UNIX systems. On Windows it delivers directly to an SMTP server, while on a UNIX system it uses a local command to hand off to the system's own MTA.

The upshot of all this is that on a Windows system your  message and headers must use the standard line endings \r\n as prescribed by the email specs. On a UNIX system the MTA's "sendmail" interface assumes that recieved data will use UNIX line endings and will turn any \n to \r\n, so you must supply only \n to mail() on a UNIX system to avoid the MTA hypercorrecting to \r\r\n.

If you use plain old \n on a Windows system, some MTAs will get a little upset. qmail in particular will refuse outright to accept any message that has a lonely \n without an accompanying \r.

Porjo

12 years ago

Make sure you enclose \r\n in double quotes (not single quotes!) so that PHP can translate that into the correct linefeed code

pavel.lint at vk.com

10 years ago

Here's a small handy function I use to send email in UTF-8.

function mail_utf8($to, $from_user, $from_email,
                                            
$subject = '(No subject)', $message = '')
   {
     
$from_user = "=?UTF-8?B?".base64_encode($from_user)."?=";
     
$subject = "=?UTF-8?B?".base64_encode($subject)."?=";$headers = "From: $from_user <$from_email>\r\n".
              
"MIME-Version: 1.0" . "\r\n" .
              
"Content-type: text/html; charset=UTF-8" . "\r\n";

     return

mail($to, $subject, $message, $headers);
   }
?>

Mark Simon

3 years ago

It is worth noting that you can set up a fake sendmail program using the sendmail_path directive in php.ini.

Despite the comment in that file, sendmail_path also works for Window. From https://www.php.net/manual/en/mail.configuration.php#ini.sendmail-path:

This directive works also under Windows. If set, smtp, smtp_port and sendmail_from are ignored and the specified command is executed.

eeeugeneee

5 years ago

Send mail with minimal requirements from email services.

    $encoding = "utf-8";// Preferences for Subject field
   
$subject_preferences = array(
       
"input-charset" => $encoding,
       
"output-charset" => $encoding,
       
"line-length" => 76,
       
"line-break-chars" => "\r\n"
   
);// Mail header
   
$header = "Content-type: text/html; charset=".$encoding." \r\n";
   
$header .= "From: ".$from_name." <".$from_mail."> \r\n";
   
$header .= "MIME-Version: 1.0 \r\n";
   
$header .= "Content-Transfer-Encoding: 8bit \r\n";
   
$header .= "Date: ".date("r (T)")." \r\n";
   
$header .= iconv_mime_encode("Subject", $mail_subject, $subject_preferences);// Send mail
   
mail($mail_to, $mail_subject, $mail_message, $header);
?>

rexlorenzo at gmail dot com

10 years ago

Be careful to not put extra spaces for the $headers variable.

For example, this didn't work on our servers:

$headers = "From: $from \r\n Bcc: $bcc \r\n";

But this did:

$headers = "From: $from\r\nBcc: $bcc\r\n";

Notice the removal of the spaces around the first \r\n.

Max AT

10 years ago

To define a mail sensitivity you have to put this line in the headers:

        $headers = "MIME-Version: 1.0\n" ;
       
$headers .= "Content-Type: text/html; charset=\"iso-8859-1\"\n";$headers .= "Sensitivity: Personal\n";$status   = mail($to, $subject, $message,$headers);
?>

Possible Options:
Sensitivity: Normal, Personal, Private and Company-Confidential

These will be recognised and handled in Outlook, Thunderbird and others.

php dot net at schrecktech dot com

17 years ago

When sending MIME email make sure you follow the documentation with the "70" characters per line...you may end up with missing characters...and that is really hard to track down...