Asked  7 Months ago    Answers:  5   Viewed   32 times

In PHP, I have a string like this:

$string = " MIME-Version: bla bla bla";

How do i get the email address only? Is there any easy way to get the value??



If you're not sure which part of the space-separated string is the e-mail address, you can split the string by spaces and use

filter_var($email, FILTER_VALIDATE_EMAIL)

on each substring.

Wednesday, March 31, 2021
answered 7 Months ago

There are two problems here:

  • You are not removing the address from the mail, so when you add a second one, the first one is still there and both will see the other address.
  • You are using a header redirect in your loop without terminating your script. This can cause code after the redirect to run, but there is no guarantee for how much and how long.

The first problem you can solve by clearing the recipients at the end of the loop:


As for the second problem, you should not redirect anywhere inside the loop and when you redirect after all messages have been sent, you should exit your scipt using exit; so that nothing gets executed after that.

Saturday, May 29, 2021
answered 5 Months ago

I think you need to use the PropertyAccessor.

$smtpAddress = $recip.PropertyAccessor.GetProperty($PR_SMTP_ADDRESS)

See here (Warning! VBA):

Thursday, August 5, 2021
answered 3 Months ago
For sending mail with attachment using php mail().Try this code:


 //If there is no error, send the email
 if(isset($_POST['ur_submit_button_name'])) {
  $EmailTo = "";
  $EmailFrom = "";
  $EmailSubject = "The Email Subject";

  $separator = md5(time());

  // carriage return type (we use a PHP end of line constant)
  $eol = PHP_EOL;

  // attachment name
  $filename = "";//store that zip file in ur root directory
  $attachment = chunk_split(base64_encode(file_get_contents('')));

  // main header
  $headers  = "From: ".$from.$eol;
  $headers .= "MIME-Version: 1.0".$eol; 
  $headers .= "Content-Type: multipart/mixed; boundary="".$separator.""";

  // no more headers after this, we start the body! //

  $body = "--".$separator.$eol;
  $body .= "Content-Transfer-Encoding: 7bit".$eol.$eol;
  $body .= "This is a MIME encoded message.".$eol;

  // message
  $body .= "--".$separator.$eol;
  $body .= "Content-Type: text/html; charset="iso-8859-1"".$eol;
  $body .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
  $body .= $message.$eol;

  // attachment
  $body .= "--".$separator.$eol;
  $body .= "Content-Type: application/octet-stream; name="".$filename.""".$eol; 
  $body .= "Content-Transfer-Encoding: base64".$eol;
  $body .= "Content-Disposition: attachment".$eol.$eol;
  $body .= $attachment.$eol;
  $body .= "--".$separator."--";

  // send message
  if (mail($to, $subject, $body, $headers)) {
  echo "mail sent";
  } else {
  echo "Error,Mail not sent";


Saturday, August 7, 2021
answered 3 Months ago

This code assumes names are in column A. It further assumes that the name of the address book you are tapping into is named "Contacts", and that they are formatted according to your diagram.

Option Explicit 
Private Sub GetAddresses() 
Dim o, AddressList, AddressEntry 
Dim c As Range, r As Range, AddressName As String 
Set o = CreateObject("Outlook.Application") 
Set AddressList = o.Session.AddressLists("Contacts") 
 'Change this range accordingly
Set r = Range("A1:A25") 
  For Each c In r 
    AddressName = c.Value 
    For Each AddressEntry In AddressList.AddressEntries 
        If AddressEntry.Name = AddressName Then 
            c.Offset(0, 1).Value = AddressEntry.Address 
            Exit For 
        End If 
    Next AddressEntry 
  Next c 
End Sub 

If the addresses are in the Global Address List, In Outlook, go to Tools--> Address Book. Then use the drop-down list to identify which list your addresses are in. Replace "Contacts" in the code with the name of the address book the addresses are stored in.

I didn't write this, I found it on Ozgrid and modified a couple of things to fit your situation. It may take a little tweaking for your application. Hope this helps or gets you going in the right direction.

Wednesday, August 25, 2021
Angshuman Agarwal
answered 2 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :