Viewed   76 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.

Friday, August 12, 2022

You can use preg_replace to do it.

for emails:

$pattern = "/[^@s]*@[^@s]*.[^@s]*/";
$replacement = "[removed]";
preg_replace($pattern, $replacement, $string);

for urls:

$pattern = "/[a-zA-Z]*[://]*[A-Za-z0-9-_]+.+[A-Za-z0-9./%&=?-_]+/i";
$replacement = "[removed]";
preg_replace($pattern, $replacement, $string);


PHP manual entry:

Credit where credit is due: email regex taken from preg_match manpage, and URL regex taken from:

Saturday, November 5, 2022

Dont need to do any conversion first of all. So you can get rid of $code = (string)$code . ''; and all the strval() calls. You $message can be set as thus:

$message = "Winner information follows:rnEmail: ".$email."rnConfirmation Code: ".$code;

Also, it doesnt look like you are including the code in your second email. So the whole thing changed would look like this:

$myFile = "winners.txt";
$fh = fopen($myFile, 'a') or die("can't open file");
$email = $_POST['email'];
$code = $_POST['code'];
$message = "Winner information follows:rnEmail: ".$email."rnConfirmation Code: ".$code;
fwrite($fh, $email);
fwrite($fh, $code);
mail("", "Winning Notice ST", $message);
mail($email, "Winning Notice CT", 'Congrats, you won a free amazon gift card at If the following confirmation code matches the one in our records you will receive your reward. The code follows: '.$code);

One other thing to note is that you might want to put $email through some sanitizaiton checks to verify it is a valid email address.

Friday, December 23, 2022

I think you need to use the PropertyAccessor.

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

See here (Warning! VBA):

Saturday, September 10, 2022

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.

Tuesday, August 16, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :